[英]Python: Nosetests with multiple files
This is a broad question because no one seems to have found a solution to it as yet so I think asking to see a working example might prove more useful. 这是一个广泛的问题,因为似乎还没有人找到解决方案,因此我认为要求看到一个可行的例子可能会更有用。 So here goes:
因此,这里去:
Has anyone run a nosetests on a python project using imports of multiple files/packages? 有没有人使用多个文件/包的导入在python项目上运行鼻子测试?
What I mean is, do you have a directory listing such as: 我的意思是,您是否有目录列表,例如:
project/
|
|____app/
|___main.py
|___2ndFile.py
|___3rdFile.py
|____tests/
|____main_tests.py
Where your main.py imports multiple files and you perform a nosetests from the project file of utilizing a test script in the main_tests.py file? 您的main.py导入了多个文件,并且您使用main_tests.py文件中的测试脚本从项目文件中进行了鼻子测试? If so please can you screen shot your import section both of all your main files and your main_tests.py file?
如果是这样,请您对所有主文件和main_tests.py文件的导入部分进行屏幕截图吗?
This seems to be a major issue in nosetests, with no apparent solution: 这似乎是鼻子测试中的一个主要问题,没有明显的解决方案:
2ndFile.py
, 3rdFile.py
won't actually work (rename them). 2ndFile.py
和3rdFile.py
实际上将无法工作(将其重命名)。 __init__.py
inside the app directory, for it to be considered a package, so add that (it can be empty file). __init__.py
,它才能被视为一个包,因此添加它(它可以是空文件)。 __init__.py
in the tests directory! __init__.py
! main_tests.py
should look like from app.main import blah
main_tests.py
的import语句应该看起来像from app.main import blah
project
directory needs to be in your sys.path
. project
目录的绝对路径必须在sys.path
。 To achieve this, set an environment variable: export PYTHONPATH=/path/to/project
export PYTHONPATH=/path/to/project
Now running nosetests should work. 现在运行鼻子测试应该可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.