From 42d8ee43a2222a04f4bf9c97ce65291b497f1094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cardona?= Date: Thu, 25 Jun 2015 17:52:04 +0200 Subject: [testlib] Fix datadir property (closes #294478) Quoting `pydoc __import__`: "When importing a module from a package, note that __import__('A.B', ...) returns package A". `importlib.import_module` will always return module A.B in this respect. The underlying problem is that, when running test using something else than pytest this `__import__` call will generate wrong results. For instance, considering from CubicWeb tests, running: python -m unittest cubicweb.test.unittest_cwconfig.CubicWebConfigurationTC.test_appobjects_path __import__('cubicweb.test.unittest_cwconfig') will return the 'cubicweb' module, not 'cubicweb.test.unittest_cwconfig'. Since the module is imported (`cls` is a subclass coming from it), we can just look it up in sys.modules. This is part of an attempt to use something else than pytest to run tests in CubicWeb. --- logilab/common/testlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logilab/common/testlib.py b/logilab/common/testlib.py index 6f576e9..bb84aaa 100644 --- a/logilab/common/testlib.py +++ b/logilab/common/testlib.py @@ -484,7 +484,7 @@ class TestCase(unittest.TestCase): NOTE: this is a logilab's standard """ - mod = __import__(cls.__module__) + mod = sys.modules[cls.__module__] return osp.join(osp.dirname(osp.abspath(mod.__file__)), 'data') # cache it (use a class method to cache on class since TestCase is # instantiated for each test run) -- cgit v1.2.1