Skip to content
Snippets Groups Projects
Unverified Commit c158a31b authored by Jeremy Bowman's avatar Jeremy Bowman Committed by GitHub
Browse files

Merge pull request #18636 from edx/jmbowman/TE-2659

TE-2659 Fix coverage with remote xdist workers
parents 18edbf60 2580e08b
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import memcache
from lazy import lazy
from path import Path as path
from paver.easy import sh
from six.moves import configparser
from pavelib.utils.cmd import django_cmd
......@@ -251,6 +252,22 @@ class Env(object):
)
return unicode(value).strip()
@classmethod
def covered_modules(cls):
"""
List the source modules listed in .coveragerc for which coverage
will be measured.
"""
coveragerc = configparser.RawConfigParser()
coveragerc.read(cls.PYTHON_COVERAGERC)
modules = coveragerc.get('run', 'source')
result = []
for module in modules.split('\n'):
module = module.strip()
if module:
result.append(module)
return result
@lazy
def env_tokens(self):
"""
......@@ -295,3 +312,15 @@ class Env(object):
Return a dictionary of feature flags configured by the environment.
"""
return self.env_tokens.get('FEATURES', dict())
@classmethod
def rsync_dirs(cls):
"""
List the directories that should be synced during pytest-xdist
execution. Needs to include all modules for which coverage is
measured, not just the tests being run.
"""
result = set()
for module in cls.covered_modules():
result.add(module.split('/')[0])
return result
......@@ -119,6 +119,23 @@ class SystemTestSuite(PytestSuite):
self.processes = int(self.processes)
def _under_coverage_cmd(self, cmd):
"""
If self.run_under_coverage is True, it returns the arg 'cmd'
altered to be run under coverage. It returns the command
unaltered otherwise.
"""
if self.run_under_coverage:
if self.xdist_ip_addresses:
for module in Env.covered_modules():
cmd.append('--cov')
cmd.append(module)
else:
cmd.append('--cov')
cmd.append('--cov-report=')
return cmd
@property
def cmd(self):
if self.django_toxenv:
......@@ -148,12 +165,8 @@ class SystemTestSuite(PytestSuite):
xdist_string = '--tx ssh=ubuntu@{}//python="source /edx/app/edxapp/edxapp_env; ' \
'python"//chdir="/edx/app/edxapp/edx-platform"'.format(ip)
cmd.append(xdist_string)
already_synced_dirs = set()
for test_path in self.test_id.split():
test_root_dir = test_path.split('/')[0]
if test_root_dir not in already_synced_dirs:
cmd.append('--rsyncdir {}'.format(test_root_dir))
already_synced_dirs.add(test_root_dir)
for rsync_dir in Env.rsync_dirs():
cmd.append('--rsyncdir {}'.format(rsync_dir))
else:
if self.processes == -1:
cmd.append('-n auto')
......@@ -256,12 +269,8 @@ class LibTestSuite(PytestSuite):
xdist_string = '--tx ssh=ubuntu@{}//python="source /edx/app/edxapp/edxapp_env; ' \
'python"//chdir="/edx/app/edxapp/edx-platform"'.format(ip)
cmd.append(xdist_string)
already_synced_dirs = set()
for test_path in self.test_id.split():
test_root_dir = test_path.split('/')[0]
if test_root_dir not in already_synced_dirs:
cmd.append('--rsyncdir {}'.format(test_root_dir))
already_synced_dirs.add(test_root_dir)
for rsync_dir in Env.rsync_dirs():
cmd.append('--rsyncdir {}'.format(rsync_dir))
if self.eval_attr:
cmd.append("-a '{}'".format(self.eval_attr))
......@@ -277,7 +286,12 @@ class LibTestSuite(PytestSuite):
unaltered otherwise.
"""
if self.run_under_coverage:
cmd.append('--cov')
if self.xdist_ip_addresses:
for module in Env.covered_modules():
cmd.append('--cov')
cmd.append(module)
else:
cmd.append('--cov')
if self.append_coverage:
cmd.append('--cov-append')
cmd.append('--cov-report=')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment