github.phpd.cn/thought-machine/please@v12.2.0+incompatible/test/python_rules/python_coverage_test.py (about) 1 import sys 2 import unittest 3 4 5 class PythonCoverageTest(unittest.TestCase): 6 """Tests that we can import parts of the coverage module. 7 8 By default it's not trivial to import binary modules from inside a pex. Also we need to package 9 relevant versions of the tracer module, which can't work for every OS, but it'd be nice to 10 cover at least a few since it improves performance quite a bit. 11 """ 12 13 @classmethod 14 def setUpClass(cls): 15 """Must ensure coverage is set up before we can import tracer.""" 16 import __main__ as test_main 17 test_main.initialise_coverage() 18 19 def test_can_import_coverage(self): 20 """Test we can import the coverage module OK.""" 21 import coverage 22 self.assertIsNotNone(coverage) 23 24 @unittest.skipIf(sys.platform == 'darwin' and sys.version_info.major < 3, 25 'Not working on OSX python2 at present due to symbol errors') 26 def test_can_import_tracer(self): 27 """Test we can import the binary tracer module.""" 28 from coverage import tracer 29 self.assertIsNotNone(tracer)