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:

AdvancedDataRegressionFixture(datadir, …)

Subclass of DataRegressionFixture with support for additional types.

AdvancedFileRegressionFixture(datadir, …)

Subclass of FileRegressionFixture with UTF-8 by default and some extra methods.

SupportsAsDict

typing.Protocol for classes like collections.namedtuple() and typing.NamedTuple which implement an _asdict() method.

Functions:

advanced_data_regression(datadir, …)

Pytest fixture for performing regression tests on lists, dictionaries and namedtuples.

advanced_file_regression(datadir, …)

Pytest fixture for performing regression tests on strings, bytes and files.

check_file_regression(data, file_regression)

Check the given data against that in the reference file.

check_file_output(filename, file_regression)

Check the content of the given text file against the reference file.

class AdvancedDataRegressionFixture(datadir, original_datadir, request)[source]

Bases: DataRegressionFixture

Subclass of DataRegressionFixture with support for additional types.

The following types and their subclasses are supported:

check(data_dict, basename=None, fullpath=None)[source]

Checks data against 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. Default None.

  • fullpath (Optional[str]) – The complete path to use as a reference file. This option will ignore datadir fixture 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. Default None.

Note

basename and fullpath are exclusive.

class AdvancedFileRegressionFixture(datadir, original_datadir, request)[source]

Bases: FileRegressionFixture

Subclass of FileRegressionFixture with 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
check_bytes(contents, **kwargs)[source]

Checks the bytes contents against a previously recorded version, or generates a new file.

Parameters
check_file(filename, extension=None, newline='\n', **kwargs)[source]

Check the content of the given text file against the reference file.

Parameters
protocol SupportsAsDict[source]

Bases: Protocol

typing.Protocol for classes like collections.namedtuple() and typing.NamedTuple which implement an _asdict() method.

This protocol is runtime checkable.

Classes that implement this protocol must have the following methods / attributes:

_asdict()[source]

Return a new dict which maps field names to their corresponding values.

Return type

Dict[str, Any]

__non_callable_proto_members__ = {}

Type:    set

fixture advanced_data_regression[source]

Scope:    function

Pytest fixture for performing regression tests on lists, dictionaries and namedtuples.

Return type

AdvancedDataRegressionFixture

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

AdvancedFileRegressionFixture

check_file_regression(data, file_regression, extension='.txt', **kwargs)[source]

Check the given data against that in the reference file.

Parameters
Return type

bool

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
Return type

bool