Skip to content

Commit 55da159

Browse files
committed
test(coverage): add a test to check the sys.path under bzlmod
This is to answers questions like #1196
1 parent 00dd72d commit 55da159

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

examples/bzlmod/test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,42 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
import pathlib
17+
import sys
1518
import unittest
1619

1720
from lib import main
1821

1922

2023
class ExampleTest(unittest.TestCase):
24+
def test_coverage(self):
25+
for i, path in enumerate(sys.path[1:-2]):
26+
paths = ",\n ".join(sys.path)
27+
28+
self.assertFalse(
29+
"/coverage" in path,
30+
f"Expected {i + 2}th '{path}' to not contain 'coverage.py' paths, "
31+
f"sys.path has {len(sys.path)} items:\n {paths}",
32+
)
33+
34+
first_item, last_item = sys.path[0], sys.path[-1]
35+
self.assertFalse(
36+
first_item.endswith("coverage"),
37+
f"Expected the first item in sys.path '{first_item}' to not be related to coverage",
38+
)
39+
if os.environ.get("COVERAGE_MANIFEST"):
40+
# we are running under the 'bazel coverage :test'
41+
self.assertTrue(
42+
"pypi__coverage_cp" in last_item,
43+
f"Expected {last_item} to be related to coverage",
44+
)
45+
self.assertEqual(pathlib.Path(last_item).name, "coverage")
46+
else:
47+
self.assertFalse(
48+
"coverage" in last_item, f"Expected coverage tooling to not be present"
49+
)
50+
2151
def test_main(self):
2252
self.assertEquals(
2353
"""\

0 commit comments

Comments
 (0)