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

Function test_dont_collect_non_function_callable

testing/python/collect.py:1279–1304  ·  view source on GitHub ↗

Test for issue https://github.com/pytest-dev/pytest/issues/331 In this case an INTERNALERROR occurred trying to report the failure of a test like this one because pytest failed to get the source lines.

(pytester: Pytester)

Source from the content-addressed store, hash-verified

1277
1278@pytest.mark.filterwarnings("default::pytest.PytestCollectionWarning")
1279def test_dont_collect_non_function_callable(pytester: Pytester) -> None:
1280 """Test for issue https://github.com/pytest-dev/pytest/issues/331
1281
1282 In this case an INTERNALERROR occurred trying to report the failure of
1283 a test like this one because pytest failed to get the source lines.
1284 """
1285 pytester.makepyfile(
1286 """
1287 class Oh(object):
1288 def __call__(self):
1289 pass
1290
1291 test_a = Oh()
1292
1293 def test_real():
1294 pass
1295 """
1296 )
1297 result = pytester.runpytest()
1298 result.stdout.fnmatch_lines(
1299 [
1300 "*collected 1 item*",
1301 "*test_dont_collect_non_function_callable.py:2: *cannot collect 'test_a' because it is not a function*",
1302 "*1 passed, 1 warning in *",
1303 ]
1304 )
1305
1306
1307def test_class_injection_does_not_break_collection(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected