def test_doctest_module_session_fixture(self, pytester: Pytester):
        """Test that session fixtures are initialized for doctest modules (#768)."""
        # session fixture which changes some global data, which will
        # be accessed by doctests in a module
        pytester.makeconftest(
            """
            import pytest
            import sys

            @pytest.fixture(autouse=True, scope='session')
            def myfixture():
                assert not hasattr(sys, 'pytest_session_data')
                sys.pytest_session_data = 1
                yield
                del sys.pytest_session_data
        """
        )
        pytester.makepyfile(
            foo="""
            import sys

            def foo():
              '''
              >>> assert sys.pytest_session_data == 1
              '''

            def bar():
              '''
              >>> assert sys.pytest_session_data == 1
              '''
        """
        )
        result = pytester.runpytest("--doctest-modules")
        result.stdout.fnmatch_lines(["*2 passed*"])
Test that session fixtures are initialized for doctest modules (#768).
testing/test_doctest.py