【发布时间】:2015-12-17 17:17:42
【问题描述】:
我的鼻子有问题。 我想在测试目录中运行测试,但我不希望鼻子更改工作目录。这是因为我在我的库和单元测试本身中使用了相对导入。
首先是目录结构:
app_dir
app.py
library_dir
tests_dir
test_1.py
test_2.py
我目前正在 app_dir 目录中运行这样的测试:
python -m unittest discover -s library_dir.tests_dir
这很好用。
现在,我想用鼻子(nosetests)来做这个。
当我尝试时,我得到以下信息:
nosetests library_dir.tests_dir --collect-only -vv
Failure: SystemError (Parent module '' not loaded, cannot perform relative import) ... ok
Failure: SystemError (Parent module '' not loaded, cannot perform relative import) ... ok
我已经看过关于 SO 的类似问题(有很多),我可以看到的一个关于这个问题的建议是从 unittest 本身中删除相对导入,但我喜欢这种模式。此外,如果我确实更改为绝对导入,我会得到一个
(No module named '<the_module_under_test')
nose 有什么方法可以从目录中查找测试(例如 -w 选项提供的 BUT 保持工作目录与调用nose 的终端的工作目录相同?
【问题讨论】:
标签: python unit-testing nose