coincidence.regressions
Regression test helpers.
To enable the fixtures in this module add the following to conftest.py in your test directory:
pytest_plugins = ("coincidence", )
Classes:
|
Subclass of |
|
Subclass of |
|
Functions:
|
Pytest fixture for performing regression tests on lists, dictionaries and namedtuples. |
|
Pytest fixture for performing regression tests on strings, bytes and files. |
|
Check the given data against that in the reference file. |
|
Check the content of the given text file against the reference file. |
-
class
AdvancedDataRegressionFixture(datadir, original_datadir, request)[source] Bases:
DataRegressionFixtureSubclass of
DataRegressionFixturewith support for additional types.The following types and their subclasses are supported:
collections.abc.Mapping,typing.Mapping(includingdictandtyping.Dict)collections.abc.Sequence,typing.Sequence(includinglist,typing.Tupleetc.)types.MappingProxyType(cannot be subclassed)_pytest.capture.CaptureResult(the type ofcapsys.readouterr())Any type which implements the
SupportsAsDictprotocol (includingcollections.namedtuple()andtyping.NamedTuple)
-
check(data_dict, basename=None, fullpath=None)[source] Checks
dataagainst a previously recorded version, or generates a new file.- Parameters
data_dict (
Union[Sequence,SupportsAsDict,Mapping,MappingProxyType,CaptureResult])basename (
Optional[str]) – The basename of the file to test/record. If not given the name of the test is used. DefaultNone.fullpath (
Optional[str]) – The complete path to use as a reference file. This option will ignoredatadirfixture when reading expected files, but will still use it to write obtained files. Useful if a reference file is located in the session data dir, for example. DefaultNone.
Note
basenameandfullpathare exclusive.
-
class
AdvancedFileRegressionFixture(datadir, original_datadir, request)[source] Bases:
FileRegressionFixtureSubclass of
FileRegressionFixturewith UTF-8 by default and some extra methods.New in version 0.2.0.
Methods:
check(contents[, encoding, extension, …])Checks the contents against a previously recorded version, or generates a new file.
check_bytes(contents, **kwargs)Checks the bytes contents against a previously recorded version, or generates a new file.
check_file(filename[, extension, newline])Check the content of the given text file against the reference file.
-
check(contents, encoding='UTF-8', extension='.txt', newline=None, basename=None, fullpath=None, binary=False, obtained_filename=None, check_fn=None)[source] Checks the contents against a previously recorded version, or generates a new file.
- Parameters
contents (
Union[str,StringList])extension (
str) – The extension of the reference file. Default'.txt'.**kwargs – Additional keyword arguments passed to
pytest_regressions.file_regression.FileRegressionFixture.check().
See also
-
check_bytes(contents, **kwargs)[source] Checks the bytes contents against a previously recorded version, or generates a new file.
- Parameters
contents (
bytes)**kwargs – Additional keyword arguments passed to
pytest_regressions.file_regression.FileRegressionFixture.check().
-
check_file(filename, extension=None, newline='\n', **kwargs)[source] Check the content of the given text file against the reference file.
- Parameters
extension (
Optional[str]) – The extension of the reference file. IfNonethe extension is determined fromfilename. DefaultNone.newline (
Optional[str]) – Controls how universal newlines mode works. Seeopen(). Default'\n'.**kwargs – Additional keyword arguments passed to
pytest_regressions.file_regression.FileRegressionFixture.check().
See also
-
-
protocol
SupportsAsDict[source] Bases:
Protocoltyping.Protocolfor classes likecollections.namedtuple()andtyping.NamedTuplewhich implement an_asdict()method.This protocol is runtime checkable.
Classes that implement this protocol must have the following methods / attributes:
-
fixture
advanced_data_regression[source] Scope: function
Pytest fixture for performing regression tests on lists, dictionaries and namedtuples.
- Return type
-
fixture
advanced_file_regression[source] Scope: function
Pytest fixture for performing regression tests on strings, bytes and files.
New in version 0.2.0.
- Return type
-
check_file_regression(data, file_regression, extension='.txt', **kwargs)[source] Check the given data against that in the reference file.
- Parameters
data (
Union[str,StringList])file_regression (
FileRegressionFixture) – The file regression fixture for the test.extension (
str) – The extension of the reference file. Default'.txt'.**kwargs – Additional keyword arguments passed to
pytest_regressions.file_regression.FileRegressionFixture.check().
- Return type
-
check_file_output(filename, file_regression, extension=None, newline='\n', **kwargs)[source] Check the content of the given text file against the reference file.
- Parameters
file_regression (
FileRegressionFixture) – The file regression fixture for the test.extension (
Optional[str]) – The extension of the reference file. IfNonethe extension is determined fromfilename. DefaultNone.newline (
Optional[str]) – Controls how universal newlines mode works. Seeopen(). Default'\n'.**kwargs – Additional keyword arguments passed to
pytest_regressions.file_regression.FileRegressionFixture.check().
- Return type