Python версия 3.7.5, покрытие 5.0.3.
Пытаясь узнать, как измерить покрытие подпроцесса, я создал небольшой проект, состоящий из 3 файлов.
main.py:
import subprocess
import coverage
coverage.process_startup()
subprocess.run(['python', 'subprocess_script.py'])
subprocess_script.py:
print('123')
.coverager c:
[run]
branch = True
data_file = coverage-data-new
source = .
Переменная среды "COVERAGE_PROCESS_START" ссылается на .coverager c в этом проекте.
После выполнения coverage run main.py
я получаю эту ошибку:
C:\Users\Kirill.Brusinets\PycharmProjects\test_subprocess_coverage>coverage run main.py
123
self._collectors:
<Collector at 0x2f75f48: CTracer>
_run_module_as_main : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\runpy.py:193
_run_code : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\runpy.py:85
<module> : C:\Users\Kirill.Brusinets\AppData\Local\Programs\Python\Python37\Scripts\coverage.exe\__main__.py:9
main : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py:828
command_line : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py:555
do_run : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py:700
start : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\control.py:518
_init_for_start : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\control.py:449
__init__ : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\collector.py:111
<Collector at 0x2fede08: CTracer>
_run_module_as_main : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\runpy.py:193
_run_code : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\runpy.py:85
<module> : C:\Users\Kirill.Brusinets\AppData\Local\Programs\Python\Python37\Scripts\coverage.exe\__main__.py:9
main : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py:828
command_line : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py:555
do_run : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py:703
run : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\execfile.py:247
<module> : main.py:3
process_startup : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\control.py:1094
start : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\control.py:518
_init_for_start : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\control.py:449
__init__ : c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\collector.py:111
Traceback (most recent call last):
File "c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Kirill.Brusinets\AppData\Local\Programs\Python\Python37\Scripts\coverage.exe\__main__.py", line 9, in <module>
File "c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py", line 828, in main
status = CoverageScript().command_line(argv)
File "c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py", line 555, in command_line
return self.do_run(options, args)
File "c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\cmdline.py", line 708, in do_run
self.coverage.stop()
File "c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\control.py", line 542, in stop
self._collector.stop()
File "c:\users\kirill.brusinets\appdata\local\programs\python\python37\lib\site-packages\coverage\collector.py", line 333, in stop
"Expected current collector to be %r, but it's %r" % (self, self._collectors[-1])
AssertionError: Expected current collector to be <Collector at 0x2f75f48: CTracer>, but it's <Collector at 0x2fede08: CTracer>
Если я помещаю cover.process_startup () в subprocess_script.py, я не получаю никаких ошибки, но охват измеряется только на main.py. Как заставить это работать?