简体   繁体   中英

Test all files in Test directory with Pytest and Tox

I could execute pytest with Tox(Just type "tox" in terminal from Pycharm) successfully. But when I typed pytest -s tests in Terminal from Pycharm, Then Test was not executed. ImportError: DLL load failed: The specified module could not be found.

Even though you can see commands = pytest -s tests in tox.ini below and test was succeed in Tox, Then why I couldn't execute pytest -s tests in Terminal??

Directory Structure

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.ini

    [tox]
    envlist = py37

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

setup.cfg

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

setup.py

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

The default working dir for tox is toxinit , can you try changedir to tests .

Reference here:https://tox.readthedocs.io/en/latest/config.html#conf-changedir

I think you need to run python setup.py develop . Cause when you run TOX it's installing your project inside tox virtualenv. You need to do same thing for your local virtualenv (if you use it, I recommend).

I would recommend you to create local virtualenv with pycharm (PyCharm->File->Settings->Project->Python Interpreter->Add) and then when you run Terminal inside PyCharm you will be inside this virtualenv. The python setup.py develop . With this you can run tests localy with PyCharm (right click on tests and just run). But first choose in settings pytest as tests freamwork in PyCharm.

If you want to integrate Tox and PyCharm to work togheter and run tox tests inside PyCharm I wrote a blogpost about it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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