summaryrefslogtreecommitdiff
path: root/tests/test_concurrency.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-10-21 16:56:34 -0400
committerNed Batchelder <ned@nedbatchelder.com>2017-10-21 16:56:34 -0400
commit0b59a27f6c7cd8984c7a99fb06a07a6cc4e9b1e0 (patch)
tree8c742df0b4cff8aa507e59be2c6af371c730f864 /tests/test_concurrency.py
parentb5c6e0b5c3548e4d3d428627551f2f2661b41f0a (diff)
downloadpython-coveragepy-0b59a27f6c7cd8984c7a99fb06a07a6cc4e9b1e0.tar.gz
A little cleanup for #581
Diffstat (limited to 'tests/test_concurrency.py')
-rw-r--r--tests/test_concurrency.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py
index 5b25e4c..798f3ad 100644
--- a/tests/test_concurrency.py
+++ b/tests/test_concurrency.py
@@ -3,7 +3,7 @@
"""Tests for concurrency libraries."""
-import importlib
+import os
import random
import sys
import threading
@@ -13,6 +13,7 @@ from flaky import flaky
import coverage
from coverage import env
+from coverage.backward import import_local_file
from coverage.files import abs_file
from tests.coveragetest import CoverageTest
@@ -464,6 +465,7 @@ def test_coverage_stop_in_threads():
has_stopped_coverage = []
def run_thread():
+ """Check that coverage is stopping properly in threads."""
deadline = time.time() + 5
ident = threading.currentThread().ident
if sys.gettrace() is not None:
@@ -496,7 +498,7 @@ def test_thread_safe_save_data(tmpdir):
# Create some Python modules and put them in the path
modules_dir = tmpdir.mkdir('test_modules')
- module_names = ["m{:03d}".format(i) for i in range(1000)]
+ module_names = ["m{0:03d}".format(i) for i in range(1000)]
for module_name in module_names:
modules_dir.join(module_name + ".py").write("def f(): pass\n")
@@ -504,16 +506,19 @@ def test_thread_safe_save_data(tmpdir):
should_run = [True]
imported = []
- sys.path.insert(0, modules_dir.strpath)
+ #sys.path.insert(0, modules_dir.strpath)
+ old_dir = os.getcwd()
+ os.chdir(modules_dir.strpath)
try:
# Make sure that all dummy modules can be imported.
for module_name in module_names:
- importlib.import_module(module_name)
+ import_local_file(module_name)
def random_load():
+ """Import modules randomly to stress coverage."""
while should_run[0]:
module_name = random.choice(module_names)
- mod = importlib.import_module(module_name)
+ mod = import_local_file(module_name)
mod.f()
imported.append(mod)
@@ -542,9 +547,9 @@ def test_thread_safe_save_data(tmpdir):
for t in threads:
t.join()
- if len(imported) == 0 and duration < 10:
+ if (not imported) and duration < 10:
duration *= 2
finally:
- sys.path.remove(modules_dir.strpath)
+ os.chdir(old_dir)
should_run[0] = False