testing: take virtualenv into account when finding tests (
bug 1357201); r?glob
Now that we can run tests with multiple virtualenvs and not all tests
can be executed with all virtualenvs, we need to declare which tests
are compatible with which virtualenvs. This commit implements that
logic.
Mercurial extension and hooks tests are now marked as only compatible
with the "global" virtualenv. All UNIT_TEST_DIRS are marked as
compatible with the "global" virtualenv except for vcssync/tests,
which requires the "vcssync" virtualenv.
This means if we have the "global" virtualenv activated, we won't be
able to run tests in vcssync/tests. That's fine: we want to decouple
vcssync from the global virtualenv. More importantly, it means that
if we have the "vcssync" virtualenv activated and run `run-tests`
that *only* the vcssync/tests will be executed. This is because no
other test file is discovered when this virtualenv is activated.
MozReview-Commit-ID: Grkl1kBN1Ir
--- a/docs/vcssync/development.rst
+++ b/docs/vcssync/development.rst
@@ -16,9 +16,9 @@ Then activate the environment in your sh
$ source activate venv/vcssync/bin/activate
Running Tests
=============
To run the vcssync tests, run::
- $ ./run-tests -j4 vcssync
+ $ ./run-tests -j4
--- a/run-tests
+++ b/run-tests
@@ -122,17 +122,17 @@ if __name__ == '__main__':
hg_harness_args.extend(['--with-hg', hg])
# Always produce an XUnit result file.
hg_harness_args.extend(['--xunit',
os.path.join(HERE, 'coverage', 'results.xml')])
extensions = get_extensions(EXTDIR)
- test_files = get_test_files(extensions)
+ test_files = get_test_files(extensions, venv_name)
extension_tests = test_files['extension']
unit_tests = test_files['unit']
hook_tests = test_files['hook']
possible_tests = [os.path.normpath(os.path.abspath(a))
for a in extra[1:] if not a.startswith('-')]
# Filter out arguments that might be tests.
hg_harness_args = [a for a in hg_harness_args
--- a/testing/vcttesting/testing.py
+++ b/testing/vcttesting/testing.py
@@ -21,23 +21,33 @@ ROOT = os.path.normpath(os.path.join(HER
PYTHON_COVERAGE_DIRS = (
'hgext',
'pylib',
'hghooks',
'vcssync',
)
# Directories containing Python unit tests.
-UNIT_TEST_DIRS = [
- 'autoland/tests',
- 'git/tests',
- 'hgserver/tests',
- 'pylib',
- 'vcssync/tests',
-]
+UNIT_TEST_DIRS = {
+ 'autoland/tests': {
+ 'venvs': {'global'},
+ },
+ 'git/tests': {
+ 'venvs': {'global',},
+ },
+ 'hgserver/tests': {
+ 'venvs': {'global',},
+ },
+ 'pylib': {
+ 'venvs': {'global',},
+ },
+ 'vcssync/tests': {
+ 'venvs': {'vcssync',},
+ },
+}
# Directories whose Python unit tests we should ignore.
UNIT_TEST_IGNORES = (
'pylib/Bugsy',
'pylib/flake8',
'pylib/mccabe',
'pylib/pycodestyle',
'pylib/pyflakes',
@@ -103,28 +113,38 @@ def get_extensions(extdir):
value = value.strip().strip("'").strip('"').strip()
e['testedwith'] = set(value.split())
m[d] = e
return m
-def get_test_files(extensions):
+def get_test_files(extensions, venv):
extension_tests = []
- for e in extensions.values():
- extension_tests.extend(e['tests'])
+
+ if venv == 'global':
+ for e in extensions.values():
+ extension_tests.extend(e['tests'])
- hooks_test_dir = os.path.join(ROOT, 'hghooks', 'tests')
- hook_tests = [os.path.join(hooks_test_dir, f)
- for f in os.listdir(hooks_test_dir)
- if is_test_filename(f)]
+ hook_tests = []
+
+ if venv == 'global':
+ hooks_test_dir = os.path.join(ROOT, 'hghooks', 'tests')
+ hook_tests = [os.path.join(hooks_test_dir, f)
+ for f in os.listdir(hooks_test_dir)
+ if is_test_filename(f)]
unit_tests = []
- for base in UNIT_TEST_DIRS:
+ for base, settings in sorted(UNIT_TEST_DIRS.items()):
+ # Only add tests from path if marked as compatible with the
+ # current virtualenv.
+ if venv not in settings['venvs']:
+ continue
+
base = os.path.join(ROOT, base)
for root, dirs, files in os.walk(base):
relative = root[len(ROOT) + 1:]
if relative.startswith(UNIT_TEST_IGNORES):
continue
for f in files:
if f.startswith('test') and f.endswith('.py'):