@@ -1426,3 +1426,59 @@ def test_modules_not_importable_as_side_effect(self, testdir):
14261426 "* 1 failed in *" ,
14271427 ]
14281428 )
1429+
1430+
1431+ class TestCollectionFullPathWithoutDriveLetter :
1432+ def setup_test_file (self , testdir ):
1433+ testdir .makepyfile (
1434+ ** {
1435+ "project/tests/dummy_test.py" : """
1436+ def test(fix):
1437+ assert fix == 1
1438+ """
1439+ }
1440+ )
1441+ fn = testdir .tmpdir .join ("project/tests/dummy_test.py" )
1442+ assert fn .isfile ()
1443+
1444+ drive , path = os .path .splitdrive (str (fn ))
1445+ return path
1446+
1447+ def setup_conftest (self , testdir ):
1448+ testdir .makepyfile (
1449+ ** {
1450+ "project/conftest.py" : """
1451+ import pytest
1452+ @pytest.fixture
1453+ def fix(): return 1
1454+ """ ,
1455+ }
1456+ )
1457+
1458+ def test_module_name (self , testdir ):
1459+ """Module name resolves correctly from full path without drive letter (#7628)
1460+
1461+ Full path without drive letter makes py.path.local.relto, during Module construction,
1462+ to incorrectly report that the module path is not relative to the Session root.
1463+ """
1464+ path = self .setup_test_file (testdir )
1465+
1466+ [item ], _ = testdir .inline_genitems (path )
1467+ assert item .name == "test"
1468+ assert item .parent .name == "project/tests/dummy_test.py"
1469+
1470+ def test_module_full_path_without_drive_integration (self , testdir ):
1471+ """Collect and run test using full path except for the drive letter (#7628)
1472+
1473+ Integration test as reported to make sure we don't regress in other areas covered by
1474+ the test above.
1475+ """
1476+ self .setup_conftest (testdir )
1477+ path = self .setup_test_file (testdir )
1478+ result = testdir .runpytest (path , "-v" )
1479+ result .stdout .fnmatch_lines (
1480+ [
1481+ os .path .join ("project" , "tests" , "dummy_test.py" ) + "::test PASSED *" ,
1482+ "* 1 passed in *" ,
1483+ ]
1484+ )
0 commit comments