diff options
author | Rémi Cardona <remi.cardona@logilab.fr> | 2015-06-25 17:52:04 +0200 |
---|---|---|
committer | Rémi Cardona <remi.cardona@logilab.fr> | 2015-06-25 17:52:04 +0200 |
commit | 42d8ee43a2222a04f4bf9c97ce65291b497f1094 (patch) | |
tree | f8aa16e25c7ee464833646790b4e0f3e614b0c31 /logilab/common/testlib.py | |
parent | 39794b6da2a4506f29d42291265e913f5a49e1a3 (diff) | |
download | logilab-common-42d8ee43a2222a04f4bf9c97ce65291b497f1094.tar.gz |
[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.
Diffstat (limited to 'logilab/common/testlib.py')
-rw-r--r-- | logilab/common/testlib.py | 2 |
1 files changed, 1 insertions, 1 deletions
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) |