[英]How to run pytest with tests files in a tests directory
I have a package with the following structure:我有一个具有以下结构的包:
mypackage
|__ __init__.py
|
|__ dira
| |__ __init__.py
| |__ classa.py
|
|__ tests
|__ __init__.py
|__ test_classa.py
In test_classa.py
, I use the statement import dira
.在
test_classa.py
,我使用了import dira
语句。 The if I run the pytest tests
command from the directory mypackage
I get the following error:如果我从目录
mypackage
运行pytest tests
命令,我会收到以下错误:
(myenv) D:\work\dev\mypackage>pytest tests
============================= test session starts =============================
platform win32 -- Python 2.7.13, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: D:\work\dev\mypackage, inifile:
collected 0 items / 1 errors
=================================== ERRORS ====================================
__________________ ERROR collecting tests/test_classa.py ___________________
ImportError while importing test module 'D:\work\dev\mypackage\tests\test_classa.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests\test_classa.py:6: in <module>
import dira
E ImportError: No module named dira
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
Note that I have created a test configuration with PyCharm which works (like a charm).请注意,我已经使用 PyCharm 创建了一个测试配置,它可以工作(就像一个魅力)。 What am I missing?
我错过了什么?
Hope you can help,希望能帮到你
Allia艾莉亚
It should be import mypackage.dira
or from ..dira import ???
它应该是
import mypackage.dira
或from ..dira import ???
. .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.