summaryrefslogtreecommitdiff
path: root/tests/test_api.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-05-04 07:35:24 -0400
committerNed Batchelder <ned@nedbatchelder.com>2017-05-04 07:35:24 -0400
commit67f905e4b7002d71d7ab33b87089a876eb4ef66c (patch)
tree44bb3f7b60ca37933e1adc887367c771777cbbb2 /tests/test_api.py
parentb48ec04376ae5c9103bb73e1146473d70c1e5c8e (diff)
downloadpython-coveragepy-git-67f905e4b7002d71d7ab33b87089a876eb4ef66c.tar.gz
Refactor common test infrastructure for fiddling sys.path and finding files
Diffstat (limited to 'tests/test_api.py')
-rw-r--r--tests/test_api.py22
1 files changed, 6 insertions, 16 deletions
diff --git a/tests/test_api.py b/tests/test_api.py
index 9a3fc820..90f96548 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -15,7 +15,7 @@ from coverage.backward import StringIO, import_local_file
from coverage.misc import CoverageException
from coverage.report import Reporter
-from tests.coveragetest import CoverageTest, CoverageTestMethodsMixin
+from tests.coveragetest import CoverageTest, CoverageTestMethodsMixin, TESTS_DIR, UsingModulesMixin
class ApiTest(CoverageTest):
@@ -464,24 +464,11 @@ class NamespaceModuleTest(CoverageTest):
cov.analysis(sys.modules['namespace'])
-class UsingModulesMixin(object):
- """A mixin for importing modules from test/modules and test/moremodules."""
-
- run_in_temp_dir = False
-
- def setUp(self):
- super(UsingModulesMixin, self).setUp()
-
- self.chdir(self.nice_file(os.path.dirname(__file__), 'modules'))
-
- # Parent class saves and restores sys.path, we can just modify it.
- sys.path.append(".")
- sys.path.append("../moremodules")
-
-
class OmitIncludeTestsMixin(UsingModulesMixin, CoverageTestMethodsMixin):
"""Test methods for coverage methods taking include and omit."""
+ run_in_temp_dir = False
+
def filenames_in(self, summary, filenames):
"""Assert the `filenames` are in the keys of `summary`."""
for filename in filenames.split():
@@ -579,6 +566,9 @@ class SourceOmitIncludeTest(OmitIncludeTestsMixin, CoverageTest):
# Used to be if you omitted something executed and inside the source,
# then after it was executed but not recorded, it would be found in
# the search for unexecuted files, and given a score of 0%.
+
+ # The omit arg is by path, so need to be in the modules directory.
+ self.chdir(self.nice_file(TESTS_DIR, 'modules'))
lines = self.coverage_usepkgs(source=["pkg1"], omit=["pkg1/p1b.py"])
self.filenames_in(lines, "p1a")
self.filenames_not_in(lines, "p1b")