MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_fixture_finalizer

Method test_fixture_finalizer

testing/python/fixtures.py:2879–2911  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

2877 result.stdout.no_fnmatch_line("*error*")
2878
2879 def test_fixture_finalizer(self, pytester: Pytester) -> None:
2880 pytester.makeconftest(
2881 """
2882 import pytest
2883 import sys
2884
2885 @pytest.fixture
2886 def browser(request):
2887
2888 def finalize():
2889 sys.stdout.write_text('Finalized')
2890 request.addfinalizer(finalize)
2891 return {}
2892 """
2893 )
2894 b = pytester.mkdir("subdir")
2895 b.joinpath("test_overridden_fixture_finalizer.py").write_text(
2896 textwrap.dedent(
2897 """\
2898 import pytest
2899 @pytest.fixture
2900 def browser(browser):
2901 browser['visited'] = True
2902 return browser
2903
2904 def test_browser(browser):
2905 assert browser['visited'] is True
2906 """
2907 )
2908 )
2909 reprec = pytester.runpytest("-s")
2910 for test in ["test_browser"]:
2911 reprec.stdout.fnmatch_lines(["*Finalized*"])
2912
2913 def test_class_scope_with_normal_tests(self, pytester: Pytester) -> None:
2914 testpath = pytester.makepyfile(

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
makeconftestMethod · 0.45
mkdirMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected