@@ -857,6 +857,17 @@ def test_omit_and_include(self):
857
857
class SourceIncludeOmitTest (IncludeOmitTestsMixin , CoverageTest ):
858
858
"""Test using `source`, `include`, and `omit` when measuring code."""
859
859
860
+ def setUp (self ):
861
+ super ().setUp ()
862
+
863
+ # These tests use the TESTS_DIR/modules files, but they cd into it. To
864
+ # keep tests from cross-contaminating, we make a copy of the files.
865
+ # Since we need to import from there, we also add it to the beginning
866
+ # of sys.path.
867
+
868
+ shutil .copytree (nice_file (TESTS_DIR , "modules" ), "tests_dir_modules" )
869
+ sys .path .insert (0 , abs_file ("tests_dir_modules" ))
870
+
860
871
def coverage_usepkgs (self , ** kwargs ):
861
872
"""Run coverage on usepkgs and return the line summary.
862
873
@@ -867,7 +878,8 @@ def coverage_usepkgs(self, **kwargs):
867
878
cov .start ()
868
879
import usepkgs # pragma: nested # pylint: disable=import-error, unused-import
869
880
cov .stop () # pragma: nested
870
- data = cov .get_data ()
881
+ with self .assert_warnings (cov , []):
882
+ data = cov .get_data ()
871
883
summary = line_counts (data )
872
884
for k , v in list (summary .items ()):
873
885
assert k .endswith (".py" )
@@ -889,7 +901,7 @@ def test_source_package_as_package(self):
889
901
assert lines ['p1c' ] == 0
890
902
891
903
def test_source_package_as_dir (self ):
892
- os .chdir (nice_file ( TESTS_DIR , "modules" ) )
904
+ os .chdir ("tests_dir_modules" )
893
905
assert os .path .isdir ("pkg1" )
894
906
lines = self .coverage_usepkgs (source = ["pkg1" ])
895
907
self .filenames_in (lines , "p1a p1b" )
@@ -915,7 +927,7 @@ def test_source_package_part_omitted(self):
915
927
# the search for unexecuted files, and given a score of 0%.
916
928
917
929
# The omit arg is by path, so need to be in the modules directory.
918
- os .chdir (nice_file ( TESTS_DIR , "modules" ) )
930
+ os .chdir ("tests_dir_modules" )
919
931
lines = self .coverage_usepkgs (source = ["pkg1" ], omit = ["pkg1/p1b.py" ])
920
932
self .filenames_in (lines , "p1a" )
921
933
self .filenames_not_in (lines , "p1b" )
@@ -929,16 +941,16 @@ def test_source_package_as_package_part_omitted(self):
929
941
assert lines ['p1c' ] == 0
930
942
931
943
def test_ambiguous_source_package_as_dir (self ):
932
- # pkg1 is a directory and a pkg, since we cd into tests/modules /ambiguous
933
- os .chdir (nice_file ( TESTS_DIR , "modules" , " ambiguous") )
934
- # pkg1 defaults to directory because tests/modules /ambiguous/pkg1 exists
944
+ # pkg1 is a directory and a pkg, since we cd into tests_dir_modules /ambiguous
945
+ os .chdir ("tests_dir_modules/ ambiguous" )
946
+ # pkg1 defaults to directory because tests_dir_modules /ambiguous/pkg1 exists
935
947
lines = self .coverage_usepkgs (source = ["pkg1" ])
936
948
self .filenames_in (lines , "ambiguous" )
937
949
self .filenames_not_in (lines , "p1a p1b p1c" )
938
950
939
951
def test_ambiguous_source_package_as_package (self ):
940
- # pkg1 is a directory and a pkg, since we cd into tests/modules /ambiguous
941
- os .chdir (nice_file ( TESTS_DIR , "modules" , " ambiguous") )
952
+ # pkg1 is a directory and a pkg, since we cd into tests_dir_modules /ambiguous
953
+ os .chdir ("tests_dir_modules/ ambiguous" )
942
954
lines = self .coverage_usepkgs (source_pkgs = ["pkg1" ])
943
955
self .filenames_in (lines , "p1a p1b" )
944
956
self .filenames_not_in (lines , "p2a p2b othera otherb osa osb ambiguous" )
0 commit comments