@@ -1362,19 +1362,27 @@ def test_collect_pkg_init_and_file_in_args(pytester: Pytester) -> None:
13621362 p = subdir .joinpath ("test_file.py" )
13631363 p .write_text ("def test_file(): pass" )
13641364
1365- # NOTE: without "-o python_files=*.py" this collects test_file.py twice.
1366- # This changed/broke with "Add package scoped fixtures #2283" (2b1410895)
1367- # initially (causing a RecursionError).
1368- result = pytester .runpytest ("-v" , str (init ), str (p ))
1365+ # Just the package directory, the __init__.py module is filtered out.
1366+ result = pytester .runpytest ("-v" , subdir )
13691367 result .stdout .fnmatch_lines (
13701368 [
13711369 "sub/test_file.py::test_file PASSED*" ,
1370+ "*1 passed in*" ,
1371+ ]
1372+ )
1373+
1374+ # But it's included if specified directly.
1375+ result = pytester .runpytest ("-v" , init , p )
1376+ result .stdout .fnmatch_lines (
1377+ [
1378+ "sub/__init__.py::test_init PASSED*" ,
13721379 "sub/test_file.py::test_file PASSED*" ,
13731380 "*2 passed in*" ,
13741381 ]
13751382 )
13761383
1377- result = pytester .runpytest ("-v" , "-o" , "python_files=*.py" , str (init ), str (p ))
1384+ # Or if the pattern allows it.
1385+ result = pytester .runpytest ("-v" , "-o" , "python_files=*.py" , subdir )
13781386 result .stdout .fnmatch_lines (
13791387 [
13801388 "sub/__init__.py::test_init PASSED*" ,
@@ -1389,10 +1397,13 @@ def test_collect_pkg_init_only(pytester: Pytester) -> None:
13891397 init = subdir .joinpath ("__init__.py" )
13901398 init .write_text ("def test_init(): pass" )
13911399
1392- result = pytester .runpytest (str ( init ) )
1400+ result = pytester .runpytest (subdir )
13931401 result .stdout .fnmatch_lines (["*no tests ran in*" ])
13941402
1395- result = pytester .runpytest ("-v" , "-o" , "python_files=*.py" , str (init ))
1403+ result = pytester .runpytest ("-v" , init )
1404+ result .stdout .fnmatch_lines (["sub/__init__.py::test_init PASSED*" , "*1 passed in*" ])
1405+
1406+ result = pytester .runpytest ("-v" , "-o" , "python_files=*.py" , subdir )
13961407 result .stdout .fnmatch_lines (["sub/__init__.py::test_init PASSED*" , "*1 passed in*" ])
13971408
13981409
0 commit comments