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

Method test_basic

testing/test_assertrewrite.py:1409–1440  ·  view source on GitHub ↗

Ensure we avoid calling PathFinder.find_spec when we know for sure a certain module will not be rewritten to optimize assertion rewriting (#3918).

(self, pytester: Pytester, hook: AssertionRewritingHook)

Source from the content-addressed store, hash-verified

1407 return hook
1408
1409 def test_basic(self, pytester: Pytester, hook: AssertionRewritingHook) -> None:
1410 """
1411 Ensure we avoid calling PathFinder.find_spec when we know for sure a certain
1412 module will not be rewritten to optimize assertion rewriting (#3918).
1413 """
1414 pytester.makeconftest(
1415 """
1416 import pytest
1417 @pytest.fixture
1418 def fix(): return 1
1419 """
1420 )
1421 pytester.makepyfile(test_foo="def test_foo(): pass")
1422 pytester.makepyfile(bar="def bar(): pass")
1423 foobar_path = pytester.makepyfile(foobar="def foobar(): pass")
1424 self.initial_paths.add(foobar_path)
1425
1426 # conftest files should always be rewritten
1427 assert hook.find_spec("conftest") is not None
1428 assert self.find_spec_calls == ["conftest"]
1429
1430 # files matching "python_files" mask should always be rewritten
1431 assert hook.find_spec("test_foo") is not None
1432 assert self.find_spec_calls == ["conftest", "test_foo"]
1433
1434 # file does not match "python_files": early bailout
1435 assert hook.find_spec("bar") is None
1436 assert self.find_spec_calls == ["conftest", "test_foo"]
1437
1438 # file is an initial path (passed on the command-line): should be rewritten
1439 assert hook.find_spec("foobar") is not None
1440 assert self.find_spec_calls == ["conftest", "test_foo", "foobar"]
1441
1442 def test_pattern_contains_subdirectories(
1443 self, pytester: Pytester, hook: AssertionRewritingHook

Callers

nothing calls this directly

Calls 3

find_specMethod · 0.80
makeconftestMethod · 0.45
makepyfileMethod · 0.45

Tested by

no test coverage detected