(pytester: Pytester, stmt: str)
| 832 | |
| 833 | @pytest.mark.parametrize("stmt", ["return", "yield"]) |
| 834 | def 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 | |
| 866 | def test_non_unittest_no_setupclass_support(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected