master_test: Don't assume __file__ points to source code

When run under a test runner the unit tests are imported as modules.
This triggers .pyc generation, after which __file__ resolves to the .pyc
file.
pull/180/head
Alex Willmer 6 years ago
parent 841c2b13a1
commit 0dcaeb21a2

@ -1,3 +1,4 @@
import inspect
import unittest2
@ -9,8 +10,10 @@ class ScanCodeImportsTest(unittest2.TestCase):
func = staticmethod(mitogen.master.scan_code_imports)
def test_simple(self):
co = compile(open(__file__).read(), __file__, 'exec')
source_path = inspect.getsourcefile(ScanCodeImportsTest)
co = compile(open(source_path).read(), source_path, 'exec')
self.assertEquals(list(self.func(co)), [
(-1, 'inspect', ()),
(-1, 'unittest2', ()),
(-1, 'testlib', ()),
(-1, 'mitogen.master', ()),

Loading…
Cancel
Save