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

Function test_unittest_setup_interaction

testing/test_unittest.py:834–863  ·  view source on GitHub ↗
(pytester: Pytester, stmt: str)

Source from the content-addressed store, hash-verified

832
833@pytest.mark.parametrize("stmt", ["return", "yield"])
834def test_unittest_setup_interaction(pytester: Pytester, stmt: str) -> None:
835 pytester.makepyfile(
836 """
837 import unittest
838 import pytest
839 class MyTestCase(unittest.TestCase):
840 @pytest.fixture(scope="class", autouse=True)
841 def perclass(self, request):
842 request.cls.hello = "world"
843 {stmt}
844 @pytest.fixture(scope="function", autouse=True)
845 def perfunction(self, request):
846 request.instance.funcname = request.function.__name__
847 {stmt}
848
849 def test_method1(self):
850 assert self.funcname == "test_method1"
851 assert self.hello == "world"
852
853 def test_method2(self):
854 assert self.funcname == "test_method2"
855
856 def test_classattr(self):
857 assert self.__class__.hello == "world"
858 """.format(
859 stmt=stmt
860 )
861 )
862 result = pytester.runpytest()
863 result.stdout.fnmatch_lines(["*3 passed*"])
864
865
866def test_non_unittest_no_setupclass_support(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
formatMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected