Pytest

Primary testing framework implementation. The most useful is class PytestContext, which compounds with testoot.pub.Basetestoot for testoot.pub.testoot initialization.

class testoot.ext.pytest.PytestContext(request, comparator: Optional[testoot.base.Comparator] = None, serializer: Optional[testoot.base.TestootSerializer] = None, ask_canonize: bool = False)[source]

Test context from Pytest

__init__(request, comparator: Optional[testoot.base.Comparator] = None, serializer: Optional[testoot.base.TestootSerializer] = None, ask_canonize: bool = False)[source]

Initializes pytest context

Parameters
  • request – standard request fixture

  • comparator – comparison for objects

  • ask_canonize – ask canonize

ask_canonize() → bool[source]

Checks that context allow canonization with user interaction. register_addoption() had to be called in conftest.py to support –canonize parameter in pytest running.

create_test_result(test_obj: any, canon_obj: any, exc: Exception)testoot.base.TestootTestResult[source]
get_comparator() → Optional[testoot.base.Comparator][source]
get_serializer() → Optional[testoot.base.TestootSerializer][source]
get_storage_name(file_type_hint: testoot.base.FileType, suffix: Optional[str] = None)[source]

Gets name for test

get_storage_name_from_filename(filename: str)[source]
pytest.register_addoption()

Call this function in conftest.py to enable canonize online such way:

def pytest_addoption(parser):
    register_addoption(parser)
class testoot.ext.pytest.PytestComparator[source]
classmethod compare(test_obj: any, canon_obj: any)[source]

Compares objects

class testoot.ext.pytest.PytestResult(*, test_obj: any, canon_obj: any, exc: Exception, context: testoot.ext.pytest.PytestContext)[source]

Pytest test result

__init__(*, test_obj: any, canon_obj: any, exc: Exception, context: testoot.ext.pytest.PytestContext)[source]

Initialize self. See help(type(self)) for accurate signature.

format_diff() → str[source]

Format diff