Skip to content

Commit

Permalink
More pragmas to fine-tune coverage of test code
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Feb 22, 2018
1 parent 23963b4 commit edf8ff4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions metacov.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ exclude_lines =
# OS error conditions that we can't (or don't care to) replicate.
pragma: cant happen

# Obscure bugs in specific versions of interpreters, and so probably no
# longer tested.
pragma: obscure

# Jython needs special care.
pragma: only jython
skip.*Jython
Expand Down
22 changes: 11 additions & 11 deletions tests/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def test_coverage_stop_in_threads():
has_started_coverage = []
has_stopped_coverage = []

def run_thread():
def run_thread(): # pragma: nested
"""Check that coverage is stopping properly in threads."""
deadline = time.time() + 5
ident = threading.currentThread().ident
Expand All @@ -480,11 +480,11 @@ def run_thread():
cov = coverage.coverage()
cov.start()

t = threading.Thread(target=run_thread)
t.start()
t = threading.Thread(target=run_thread) # pragma: nested
t.start() # pragma: nested

time.sleep(0.1)
cov.stop()
time.sleep(0.1) # pragma: nested
cov.stop() # pragma: nested
time.sleep(0.1)

assert has_started_coverage == [t.ident]
Expand Down Expand Up @@ -513,7 +513,7 @@ def test_thread_safe_save_data(tmpdir):
for module_name in module_names:
import_local_file(module_name)

def random_load():
def random_load(): # pragma: nested
"""Import modules randomly to stress coverage."""
while should_run[0]:
module_name = random.choice(module_names)
Expand All @@ -529,12 +529,12 @@ def random_load():
cov = coverage.coverage()
cov.start()

threads = [threading.Thread(target=random_load) for _ in range(10)]
should_run[0] = True
for t in threads:
threads = [threading.Thread(target=random_load) for _ in range(10)] # pragma: nested
should_run[0] = True # pragma: nested
for t in threads: # pragma: nested
t.start()

time.sleep(duration)
time.sleep(duration) # pragma: nested

cov.stop()

Expand All @@ -546,7 +546,7 @@ def random_load():
for t in threads:
t.join()

if (not imported) and duration < 10:
if (not imported) and duration < 10: # pragma: only failure
duration *= 2

finally:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def f():
self.assertIn(msg, out)

def test_note(self):
if env.PYPY and env.PY3 and env.PYPYVERSION[:3] == (5, 10, 0):
if env.PYPY and env.PY3 and env.PYPYVERSION[:3] == (5, 10, 0): # pragma: obscure
# https://bitbucket.org/pypy/pypy/issues/2729/pypy3-510-incorrectly-decodes-astral-plane
self.skipTest("Avoid incorrect decoding astral plane JSON chars")
self.make_file(".coveragerc", """\
Expand Down Expand Up @@ -767,7 +767,7 @@ def test_coverage_run_dashm_is_like_python_dashm(self):
self.assert_tryexecfile_output(out_cov, out_py)

def test_coverage_run_dir_is_like_python_dir(self):
if sys.version_info == (3, 5, 4, 'final', 0): # pragma: not covered
if sys.version_info == (3, 5, 4, 'final', 0): # pragma: obscure
self.skipTest("3.5.4 broke this: https://bugs.python.org/issue32551")
with open(TRY_EXECFILE) as f:
self.make_file("with_main/__main__.py", f.read())
Expand Down

0 comments on commit edf8ff4

Please sign in to comment.