@@ -1392,19 +1392,27 @@ def test_collect_pkg_init_and_file_in_args(pytester: Pytester) -> None:
13921392 p = subdir .joinpath ("test_file.py" )
13931393 p .write_text ("def test_file(): pass" , encoding = "utf-8" )
13941394
1395- # NOTE: without "-o python_files=*.py" this collects test_file.py twice.
1396- # This changed/broke with "Add package scoped fixtures #2283" (2b1410895)
1397- # initially (causing a RecursionError).
1398- result = pytester .runpytest ("-v" , str (init ), str (p ))
1395+ # Just the package directory, the __init__.py module is filtered out.
1396+ result = pytester .runpytest ("-v" , subdir )
13991397 result .stdout .fnmatch_lines (
14001398 [
14011399 "sub/test_file.py::test_file PASSED*" ,
1400+ "*1 passed in*" ,
1401+ ]
1402+ )
1403+
1404+ # But it's included if specified directly.
1405+ result = pytester .runpytest ("-v" , init , p )
1406+ result .stdout .fnmatch_lines (
1407+ [
1408+ "sub/__init__.py::test_init PASSED*" ,
14021409 "sub/test_file.py::test_file PASSED*" ,
14031410 "*2 passed in*" ,
14041411 ]
14051412 )
14061413
1407- result = pytester .runpytest ("-v" , "-o" , "python_files=*.py" , str (init ), str (p ))
1414+ # Or if the pattern allows it.
1415+ result = pytester .runpytest ("-v" , "-o" , "python_files=*.py" , subdir )
14081416 result .stdout .fnmatch_lines (
14091417 [
14101418 "sub/__init__.py::test_init PASSED*" ,
@@ -1419,10 +1427,13 @@ def test_collect_pkg_init_only(pytester: Pytester) -> None:
14191427 init = subdir .joinpath ("__init__.py" )
14201428 init .write_text ("def test_init(): pass" , encoding = "utf-8" )
14211429
1422- result = pytester .runpytest (str ( init ) )
1430+ result = pytester .runpytest (subdir )
14231431 result .stdout .fnmatch_lines (["*no tests ran in*" ])
14241432
1425- result = pytester .runpytest ("-v" , "-o" , "python_files=*.py" , str (init ))
1433+ result = pytester .runpytest ("-v" , init )
1434+ result .stdout .fnmatch_lines (["sub/__init__.py::test_init PASSED*" , "*1 passed in*" ])
1435+
1436+ result = pytester .runpytest ("-v" , "-o" , "python_files=*.py" , subdir )
14261437 result .stdout .fnmatch_lines (["sub/__init__.py::test_init PASSED*" , "*1 passed in*" ])
14271438
14281439
0 commit comments