-
Notifications
You must be signed in to change notification settings - Fork 15
Description
- When a user makes a
pytestcall, this hook runs. We create the SnapshotSystem, and find all the tests that are planning to run.selfie/python/pytest-selfie/pytest_selfie/plugin.py
Lines 68 to 78 in f1325e8
@pytest.hookimpl def pytest_collection_modifyitems( session: pytest.Session, config: pytest.Config, items: List[pytest.Item] ) -> None: settings = SelfieSettingsAPI(config) system = PytestSnapshotSystem(settings) session.selfie_system = system # type: ignore _initSelfieSystem(system) for item in items: (file, _, testname) = item.reportinfo() system.planning_to_run(TypedPath.of_file(os.path.abspath(file)), testname)
- For each test that runs, this method gets called.
selfie/python/pytest-selfie/pytest_selfie/plugin.py
Lines 88 to 96 in f1325e8
@pytest.hookimpl(hookwrapper=True) def pytest_runtest_protocol(item: pytest.Item, nextitem: Optional[pytest.Item]): (file, _, testname) = item.reportinfo() testfile = TypedPath.of_file(os.path.abspath(file)) system: PytestSnapshotSystem = item.session.selfie_system # type: ignore system.test_start(testfile, testname) yield system.test_finish(testfile, testname) - we notify the system that a test is starting
- the test runs at the yield
- we notify the system that a test has finished
- Within that yield call, this function gets called when a test has something to report
selfie/python/pytest-selfie/pytest_selfie/plugin.py
Lines 99 to 107 in f1325e8
@pytest.hookimpl def pytest_runtest_makereport(call: pytest.CallInfo[None], item: pytest.Item): if call.excinfo is not None and call.when in ( "call", "teardown", ): system: PytestSnapshotSystem = item.session.selfie_system # type: ignore (file, _, testname) = item.reportinfo() system.test_failed(TypedPath.of_file(os.path.abspath(file)), testname) - if a test fails during the call or teardown phases, we notify the system so that GC won't run
- And at the very end we call this to mark that everything is done and we can write everything to disk
selfie/python/pytest-selfie/pytest_selfie/plugin.py
Lines 81 to 85 in f1325e8
@pytest.hookimpl def pytest_sessionfinish(session: pytest.Session, exitstatus): system: PytestSnapshotSystem = session.selfie_system # type: ignore system.finished_all_tests() _clearSelfieSystem(system) - An important asterisk is that SnapshotFiles are read / written to disk as we go, they don't wait until the end.
If you look in example-pytest-selfie, you'll see three tests which exercise the subsystems you have built to-date:
- @hssahota2 https://github.com/diffplug/selfie/blob/main/python/example-pytest-selfie/tests/simple_comment_removal_test.py
- @SDelgado-21 https://github.com/diffplug/selfie/blob/main/python/example-pytest-selfie/tests/simple_inline_test.py
- @Trickybrain https://github.com/diffplug/selfie/blob/main/python/example-pytest-selfie/tests/simple_ondisk_test.py
If you run them, you'll see that the SnapshotSystem is all wired up to them, but with some NotImplementedError along the way.
If you have something in-progress, go ahead and finish that up. Otherwise, try to get your subsystem to work in this context.