File: test-case.md

package info (click to toggle)
python-fakeredis 2.29.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,772 kB
  • sloc: python: 19,002; sh: 8; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 1,274 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# Write a new test case

There are multiple scenarios for test, with different versions of python, redis-py and redis server, etc.
The tests not only assert the validity of the expected output with FakeRedis but also with a real redis server.
That way parity of real Redis and FakeRedis is ensured.

To write a new test case for a command:

- Determine which mixin the command belongs to and the test file for
  the mixin (e.g., `string_mixin.py` => `test_string_commands.py`).
- Tests should support python 3.7 and above.
- Determine when support for the command was introduced
    - To limit the redis-server versions, it will run on use:
      `@pytest.mark.max_server(version)` and `@pytest.mark.min_server(version)`
    - To limit the redis-py version use `@run_test_if_redispy_ver('gte', version)`
      (you can use `ge`/`gte`/`lte`/`lt`/`eq`/`ne`).
- pytest will inject a redis connection to the argument `r` of the test.

Sample of running a test for redis-py v4.2.0 and above, redis-server 7.0 and above.

```python
@pytest.mark.min_server('7')
@testtools.run_test_if_redispy_ver('gte', '4.2.0')
def test_expire_should_not_expire__when_no_expire_is_set(r):
    r.set('foo', 'bar')
    assert r.get('foo') == b'bar'
    assert r.expire('foo', 1, xx=True) == 0
```