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

Method test_fixture_scopes

testing/test_doctest.py:1250–1279  ·  view source on GitHub ↗

Test that auto-use fixtures work properly with doctest modules. See #1057 and #1100.

(self, pytester, scope, enable_doctest)

Source from the content-addressed store, hash-verified

1248 @pytest.mark.parametrize("scope", SCOPES)
1249 @pytest.mark.parametrize("enable_doctest", [True, False])
1250 def test_fixture_scopes(self, pytester, scope, enable_doctest):
1251 """Test that auto-use fixtures work properly with doctest modules.
1252 See #1057 and #1100.
1253 """
1254 pytester.makeconftest(
1255 """
1256 import pytest
1257
1258 @pytest.fixture(autouse=True, scope="{scope}")
1259 def auto(request):
1260 return 99
1261 """.format(
1262 scope=scope
1263 )
1264 )
1265 pytester.makepyfile(
1266 test_1='''
1267 def test_foo():
1268 """
1269 >>> getfixture('auto') + 1
1270 100
1271 """
1272 def test_bar():
1273 assert 1
1274 '''
1275 )
1276 params = ("--doctest-modules",) if enable_doctest else ()
1277 passes = 3 if enable_doctest else 2
1278 result = pytester.runpytest(*params)
1279 result.stdout.fnmatch_lines(["*=== %d passed in *" % passes])
1280
1281 @pytest.mark.parametrize("scope", SCOPES)
1282 @pytest.mark.parametrize("autouse", [True, False])

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected