UNITSESTS从命令行工作,但不工作
我正在编写一些我想在Pycharm中调试的单元测试。调试工作正常。但是,如果我想在调试模式以外运行测试,我会得到:
C:\Users\my_name\Miniconda3\envs\feature-extraction\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --path D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py
Testing started at 5:04 PM ...
Ran 1 test in 0.002s
Launching unittests with arguments python -m unittest D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py in D:/
FAILED (errors=1)
...
...
module = __import__(module_name)
ModuleNotFoundError: No module named 'test_misc'
但是,我能够通过
"C:\Users\my_name\Miniconda3\envs\feature-extraction\python.exe" "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --path D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py
以下方式
python -m unittest D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py
在 命令行中运行测试直接从发生误差的Pycharm Run输出粘贴。
这些命令从运行到顶级项目中的任何位置时起作用。
我正在使用UNITSEST和默认运行配置,这些配置会自动在第一次运行中自动填充,例如:
具有标准项目结构,例如:
project_folder
|
|- top_level_package/
| |
| |- __init__.py
| |- sub_packages/ (containing modules)
|
|-tests/
|- __init__.py
|- package_to_test/
|
|- __init__.py
|- test_module1.py
|- test_module2.py
问题:
我如何获得单位测试以在调试模式外在Pycharm中运行?显然,我可以在调试模式下运行它们,但是后来我必须删除所有断点。
I'm writing some unit tests that I'd like to debug in pycharm. Debugging works just fine. However, if I want to run the tests outside of debug mode, I get:
C:\Users\my_name\Miniconda3\envs\feature-extraction\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --path D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py
Testing started at 5:04 PM ...
Ran 1 test in 0.002s
Launching unittests with arguments python -m unittest D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py in D:/
FAILED (errors=1)
...
...
module = __import__(module_name)
ModuleNotFoundError: No module named 'test_misc'
However, I am able to get them to run the tests in the command line with:
"C:\Users\my_name\Miniconda3\envs\feature-extraction\python.exe" "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --path D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py
OR this:
python -m unittest D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py
You will notice that both of the above commands are copied and pasted directly from the PyCharm run output where the error occurs.
These commands work when run from any location within the top level project.
I am using unittest with default run configurations which are automatically populated on first run, for example:
With a standard project structure like:
project_folder
|
|- top_level_package/
| |
| |- __init__.py
| |- sub_packages/ (containing modules)
|
|-tests/
|- __init__.py
|- package_to_test/
|
|- __init__.py
|- test_module1.py
|- test_module2.py
Question:
How do I get unit tests to run in PyCharm outside of debug mode? Obviously I could just run them in debug mode, but then I'd have to remove all of my breakpoints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的方法是将package_to_test重命名为package_to_test_t_t
在使用默认参数的Pycharm之后,开始解析软件包名称。
要在命令行上运行测试,我通常在导入软件包之前添加Unitest类(需要检查OS.Path.dirname()调用的数量,这取决于测试的目录级别。
my approach has been to rename package_to_test to package_to_test_t
After it pycharm with default params starts to resolve the package names.
To run tests on command line I usually add in unittest classes before importing my packages (need to check number of os.path.dirname() calls depending the directory levels of your test.