繁体   English   中英

使用 Pytest 和 Tox 测试 Test 目录中的所有文件

[英]Test all files in Test directory with Pytest and Tox

我可以使用 Tox 成功执行 pytest(只需在 Pycharm 的终端中输入“tox”)。 但是,当我从 Pycharm 在终端中键入pytest -s tests时,没有执行测试。 ImportError: DLL load failed: The specified module could not be found.

即使您可以在下面的tox.ini中看到commands = pytest -s tests并且在 Tox 中测试成功,那么为什么我无法在终端中执行pytest -s tests

目录结构

root
| - .tox
| - robotor # include all of source code in "robotor" directory
| - tests
| | | - unittest
| | | | - robotor
| | | | | - __init__.py
| | | | | - test_robotor.py
| | | | - __init.py
| | | - __init__.py
| - main.py
| - setup.py
| - setup.cfg
| - tox.ini

毒物

    [tox]
    envlist = py37

    [testenv:py37]
    deps = pytest
    commands = pytest -s tests  # I put test files in "tests" directory

设置.cfg

[aliases]
test=pytest
[tool:pytest]
python_files=tests/*

安装程序.py

setup(
    ~
  ~
    setup_requires=[
        'pytest-runner',
    ],
    tests_require=['pytest'],
  ~
    ~
)

tox 的默认工作目录是toxinit ,您可以尝试将其更改为tests

参考这里:https://tox.readthedocs.io/en/latest/config.html#conf-changedir

我认为您需要运行python setup.py develop 因为当您运行 TOX 时,它会将您的项目安装在 tox virtualenv 中。 你需要为你的本地 virtualenv 做同样的事情(如果你使用它,我推荐)。

我建议您使用 pycharm(PyCharm->File->Settings->Project->Python Interpreter->Add)创建本地 virtualenv,然后当您在 PyCharm 中运行终端时,您将在此 virtualenv 中。 python setup.py develop 有了这个,您可以使用 PyCharm 在本地运行测试(右键单击测试并运行)。 但首先在设置中选择 pytest 作为 PyCharm 中的测试框架。

如果你想集成 Tox 和 PyCharm 一起工作并在 PyCharm 中运行 tox 测试,我在这里写了一篇关于它的博文。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM