22
22
23
23
import pytest
24
24
25
+ # Contants derived the same as in coverage/env.py. We can't import
26
+ # that file here, it would be evaluated too early and not get the
27
+ # settings we make in this file.
28
+
29
+ CPYTHON = (platform .python_implementation () == "CPython" )
30
+ PYPY = (platform .python_implementation () == "PyPy" )
25
31
26
32
@contextlib .contextmanager
27
33
def ignore_warnings ():
@@ -73,7 +79,18 @@ def label_for_tracer(tracer):
73
79
74
80
def should_skip (tracer ):
75
81
"""Is there a reason to skip these tests?"""
76
- if tracer == "py" :
82
+ skipper = ""
83
+
84
+ # $set_env.py: COVERAGE_ONE_TRACER - Only run tests for one tracer.
85
+ only_one = os .environ .get ("COVERAGE_ONE_TRACER" )
86
+ if only_one :
87
+ if CPYTHON :
88
+ if tracer == "py" :
89
+ skipper = "Only one tracer: no Python tracer for CPython"
90
+ else :
91
+ if tracer == "c" :
92
+ skipper = "No C tracer for {}" .format (platform .python_implementation ())
93
+ elif tracer == "py" :
77
94
# $set_env.py: COVERAGE_NO_PYTRACER - Don't run the tests under the Python tracer.
78
95
skipper = os .environ .get ("COVERAGE_NO_PYTRACER" )
79
96
else :
@@ -94,7 +111,7 @@ def make_env_id(tracer):
94
111
"""An environment id that will keep all the test runs distinct."""
95
112
impl = platform .python_implementation ().lower ()
96
113
version = "%s%s" % sys .version_info [:2 ]
97
- if '__pypy__' in sys . builtin_module_names :
114
+ if PYPY :
98
115
version += "_%s%s" % sys .pypy_version_info [:2 ]
99
116
env_id = "%s%s_%s" % (impl , version , tracer )
100
117
return env_id
@@ -108,6 +125,7 @@ def run_tests(tracer, *runner_args):
108
125
if 'COVERAGE_ENV_ID' in os .environ :
109
126
os .environ ['COVERAGE_ENV_ID' ] = make_env_id (tracer )
110
127
print_banner (label_for_tracer (tracer ))
128
+
111
129
return pytest .main (list (runner_args ))
112
130
113
131
@@ -325,7 +343,7 @@ def print_banner(label):
325
343
326
344
version = platform .python_version ()
327
345
328
- if '__pypy__' in sys . builtin_module_names :
346
+ if PYPY :
329
347
version += " (pypy %s)" % "." .join (str (v ) for v in sys .pypy_version_info )
330
348
331
349
rev = platform .python_revision ()
0 commit comments