Skip to content

session

A plugin that implements the core logic of running Testwizard tests in the pytest ecosystem.

It consists of two plugins: the session.py module, which is responsible for initializing the TestWizardSession plugin, and the TestWizardSession plugin itself, which handles the lifecycle of tests and fixtures.

PLUGIN_CLASS_NAME module-attribute #

PLUGIN_CLASS_NAME: Final[str] = 'TestWizardSession'

TestWizardSession #

TestWizardSession(config: Config)

__test__ class-attribute instance-attribute #

__test__ = False

config instance-attribute #

config = config

root_dir instance-attribute #

root_dir = Path(getoption('--root-dir'))

pytest_collection_finish #

pytest_collection_finish(session: Session) -> None

Stores some metadata about the collected tests as follows:

  • Dumps info.json after test collection
  • Collect mapping item.nodeid -> metadata.uid. Then store this uid in the item stash. * It allows to load test metadata from item.stash[stash_keys.TEST_ITEM_UID].

Since xdist plugin performs collection on each worker, we are forced to use file locking to prevent collisions.

Parameters:

Name Type Description Default
session Session

pytest.Session from which we get tests

required

pytest_collection_modifyitems staticmethod #

pytest_collection_modifyitems(items: list[Item]) -> None

pytest_configure #

pytest_configure(config: Config) -> None

pytest_generate_tests #

pytest_generate_tests(metafunc: Metafunc)

pytest_runtest_logreport staticmethod #

pytest_runtest_logreport(report: TestReport) -> None

pytest_runtest_setup #

pytest_runtest_setup(item: Item) -> None

pytest_runtest_teardown #

pytest_runtest_teardown(
    item: Item, nextitem: Item | None
) -> None

pytest_tw_prepare_test_item_env #

pytest_tw_prepare_test_item_env(item: Item) -> dict

pytest_tw_run_fixture_protocol staticmethod #

pytest_tw_run_fixture_protocol(
    fixt_def: FixtureSpec,
    metadata: FixtureMetadata,
    config: Config,
) -> bool

Basic logic of fixture running

Parameters:

Name Type Description Default
fixt_def FixtureSpec

description

required
metadata FixtureMetadata

description

required
config Config

description

required

Returns:

Name Type Description
bool bool

a flag indicating whether an error occurred or not during test run

pytest_tw_run_test_item_protocol staticmethod #

pytest_tw_run_test_item_protocol(item: Item) -> bool

Basic logic of test running

Parameters:

Name Type Description Default
item Item

test item

required

Returns:

Name Type Description
bool bool

a flag indicating whether an error occurred or not during test run

pytest_tw_setup_test_item #

pytest_tw_setup_test_item(item: Item) -> None

pytest_tw_setup_test_item_env #

pytest_tw_setup_test_item_env(item: Item) -> bool

pytest_tw_teardown_test_item #

pytest_tw_teardown_test_item(
    item: Item,
) -> Generator[None, None, None]

parametrize #

parametrize(
    metafunc: Metafunc,
    argnames: str | Sequence[str],
    argvalues: Iterable[Any],
    indirect: bool = False,
) -> None

Get pytest.Metafunc and parametrize item through it.

Using the indirect=True allows to parametrize a test with a fixture receiving the values before passing them to a test

Parameters:

Name Type Description Default
metafunc Metafunc

metafunc object

required

pytest_configure #

pytest_configure(config: Config) -> None