@@ -1325,9 +1325,8 @@ def test_removing_directory_with_error(self) -> None:
1325
1325
class ProcessStartupTest (CoverageTest ):
1326
1326
"""Test that we can measure coverage in subprocesses."""
1327
1327
1328
- def setUp (self ) -> None :
1329
- super ().setUp ()
1330
-
1328
+ def make_main_and_sub (self ) -> None :
1329
+ """Create main.py and sub.py."""
1331
1330
# Main will run sub.py
1332
1331
self .make_file ("main.py" , """\
1333
1332
import os, os.path, sys
@@ -1342,6 +1341,7 @@ def setUp(self) -> None:
1342
1341
""" )
1343
1342
1344
1343
def test_patch_subprocess (self ) -> None :
1344
+ self .make_main_and_sub ()
1345
1345
self .make_file (".coveragerc" , """\
1346
1346
[run]
1347
1347
patch = subprocess
@@ -1358,6 +1358,7 @@ def test_subprocess_with_pth_files(self, _create_pth_file: None) -> None:
1358
1358
# An existing data file should not be read when a subprocess gets
1359
1359
# measured automatically. Create the data file here with bogus data in
1360
1360
# it.
1361
+ self .make_main_and_sub ()
1361
1362
data = coverage .CoverageData (".mycovdata" )
1362
1363
data .add_lines ({os .path .abspath ('sub.py' ): range (100 )})
1363
1364
data .write ()
@@ -1380,6 +1381,7 @@ def test_subprocess_with_pth_files(self, _create_pth_file: None) -> None:
1380
1381
1381
1382
def test_subprocess_with_pth_files_and_parallel (self , _create_pth_file : None ) -> None :
1382
1383
# https://github.com/nedbat/coveragepy/issues/492
1384
+ self .make_main_and_sub ()
1383
1385
self .make_file ("coverage.ini" , """\
1384
1386
[run]
1385
1387
parallel = true
@@ -1407,6 +1409,37 @@ def test_subprocess_with_pth_files_and_parallel(self, _create_pth_file: None) ->
1407
1409
)
1408
1410
assert len (data_files ) == 1 , msg
1409
1411
1412
+ def test_subprocess_in_directories (self ) -> None :
1413
+ # Bug 2025: patch=subprocess didn't find data files from subdirectory
1414
+ # subprocesses.
1415
+ self .make_file ("main.py" , """\
1416
+ import subprocess
1417
+ import sys
1418
+ print(subprocess.check_output(
1419
+ [sys.executable, "subproc.py"],
1420
+ cwd="subdir",
1421
+ encoding="utf-8",
1422
+ ))
1423
+ """ )
1424
+ self .make_file ("subdir/subproc.py" , """\
1425
+ with open("readme.txt", encoding="utf-8") as f:
1426
+ print(f.read(), end="")
1427
+ """ )
1428
+ self .make_file (".coveragerc" , """\
1429
+ [run]
1430
+ patch = subprocess
1431
+ data_file = .covdata
1432
+ """ )
1433
+ self .make_file ("subdir/readme.txt" , "hello" )
1434
+ out = self .run_command ("coverage run main.py" )
1435
+ assert out == "hello\n "
1436
+ self .run_command ("coverage combine" )
1437
+ data = coverage .CoverageData (".covdata" )
1438
+ data .read ()
1439
+ print (line_counts (data ))
1440
+ assert line_counts (data )["main.py" ] == 6
1441
+ assert line_counts (data )["subproc.py" ] == 2
1442
+
1410
1443
1411
1444
@pytest .mark .skipif (env .WINDOWS , reason = "patch=execv isn't supported on Windows" )
1412
1445
@pytest .mark .xdist_group (name = "needs_pth" )
0 commit comments