Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit fc452ca

Browse files
committed
We've got something that runs before all tests, after all tests, and before/after each test.
1 parent d271339 commit fc452ca

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

python/pytest-selfie/pytest_selfie/plugin.py

+31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional, Tuple
12
import pytest
23

34

@@ -17,3 +18,33 @@ def pytest_addoption(parser):
1718
@pytest.fixture
1819
def bar(request):
1920
return request.config.option.dest_foo
21+
22+
23+
@pytest.hookimpl
24+
def pytest_sessionstart(session: pytest.Session):
25+
print("SELFIE SESSION STARTED")
26+
pass
27+
28+
29+
@pytest.hookimpl
30+
def pytest_sessionfinish(session: pytest.Session, exitstatus):
31+
print("SELFIE SESSION FINISHED")
32+
pass
33+
34+
35+
@pytest.hookimpl(hookwrapper=True)
36+
def pytest_pyfunc_call(pyfuncitem: pytest.Function):
37+
# do_something_before_next_hook_executes()
38+
print("SELFIE start test {pytfuncitem.nodeid}")
39+
40+
outcome = yield
41+
42+
res = outcome.get_result() # will raise if outcome was exception
43+
44+
print("SELFIE end test {pytfuncitem.nodeid} with {Res}")
45+
# outcome.excinfo may be None or a (cls, val, tb) tuple
46+
# res = outcome.get_result() # will raise if outcome was exception
47+
48+
# post_process_result(res)
49+
50+
# outcome.force_result(new_res) # to override the return value to the plugin system

0 commit comments

Comments
 (0)