???? It is good, use it and enjoy ????
“Doesn't pytest have it out of the box?” – Boris Kovarsky
Surprisingly enough, it does not.
Contents: Installation | Quick Start | How does it save my time? | Examples and recipes | Reference
pip install pytest-canon
Simplest usage, a single line:
def test_case_1:
...
assert_equals_ref(very_long_multiline_string, 'test_case_1')
pytest # that's it :)
Update tests (e.g. with pytest
):
PYTEST_UPDATE_REFS=1 pytest
set_global_dir_path('other_dir')
Set different string comparison:
set_global_cast_func(lambda s: s.lower())
Customize a single test:
def test_case_1():
assert_equal_ref(long_string, 'test_case_1', cast_func=lambda s: s.lower())
-
Reason 1
??????
-
Reason 2
?????
-
Reason 3
??????
- simplest usage
- typical real life scenario
- customize a simple usage
- customize globally
- customize a simple usage and globally
Either compares a string value with a dumped one or dumps it depending on env_var
value.
Optional arguments:
dir_path
: str
or Path
, dir with dumps, default='tests/dumps'
env_var
: str
,env variable activating tests updates, default='PYTEST_UPDATE_REFS'
assert_func
: assert function (str, str) -> NoReturn
cast_func
: casting function str -> str
Global setters for every optional argument of assert_equals_ref