Obtain python coverage from child processes executed during testing
issue:https://st.yandex-team.ru/DEVTOOLS-6410
@@ -38,30 +38,8 @@ yatest_logger = logging.getLogger("ya.test")
_pytest.main.EXIT_NOTESTSCOLLECTED = 0
-COVERAGE_INSTANCE = [0]
-COVERAGE_ENV_NAME = 'PYTHON_COVERAGE_PREFIX'
SHUTDOWN_REQUESTED = False
-# Start coverage collection as soon as possible to avoid missing coverage for modules imported from plugins
-if COVERAGE_ENV_NAME in os.environ:
- try:
- import coverage
- except ImportError:
- coverage = None
- logging.exception("Failed to import coverage module - no coverage will be collected")
-
- if coverage:
- cov = coverage.Coverage(
- data_file=os.environ.get(COVERAGE_ENV_NAME),
- concurrency=['multiprocessing', 'thread'],
- auto_data=True,
- branch=True,
- # debug=['pid', 'trace', 'sys', 'config'],
- )
- cov.start()
- COVERAGE_INSTANCE[0] = cov
- logging.info("Coverage will be collected during testing. pid: %d", os.getpid())
-
def to_str(s):
if six.PY2 and isinstance(s, six.text_type):
@@ -219,11 +197,6 @@ def pytest_configure(config):
if envvar + '_ORIGINAL' in os.environ:
os.environ[envvar] = os.environ[envvar + '_ORIGINAL']
- config.coverage = None
- if COVERAGE_INSTANCE[0]:
- cov_prefix = os.environ[COVERAGE_ENV_NAME]
- config.coverage_data_dir = os.path.dirname(cov_prefix)
-
if config.option.root_dir:
config.rootdir = config.invocation_dir = py.path.local(config.option.root_dir)
@@ -253,8 +226,11 @@ def pytest_configure(config):
def _smooth_shutdown(*args):
- if COVERAGE_INSTANCE[0]:
- COVERAGE_INSTANCE[0].stop()
+ try:
+ import library.python.coverage
+ library.python.coverage.stop_coverage_tracing()
+ except ImportError:
+ pass
pytest.exit("Smooth shutdown requested")
