How do I make PyCharm take the testing configurati

2019-08-29 01:39发布

问题:

How do I make PyCharm take the testing configuration from setup.cfg, a file which was created by PyScaffold?

I did enable PyTest from Settings -> Tools -> Python Integrated Tools -> Testing


What I have until now is a configuration saved in the Python tests section, with:

Target: Script path = C:...\setup.py

Additional arguments: test


But this is what I'm getting when I run it:

[...] ERROR: file not found: test

Or how do I replicate the same testing configuration in PyCharm, as I have in setup.cfg?

console_scripts =
program = program.main:run

[test]
# py.test options when running `python setup.py test`
# addopts = --verbose
extras = True

[tool:pytest]
# Options for py.test:
# Specify command line options as you would do when invoking py.test directly.
# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml
# in order to write a coverage file that can be read by Jenkins.
addopts =
--cov reddit_users_info --cov-report term-missing
--verbose

[...]

testpaths = tests

回答1:

  1. Open the project directory and configure it to use the venv created. At script path you would have src\program\program.py, at parameters you could add -vv.

  2. Enable PyTest from Settings -> Tools -> Python Integrated Tools -> Testing

  3. Add a run configuration, but add one for testing as well: Edit Configurations -> + -> Python tests -> pytest.

  4. Run the tests. It will work if you've installed the packages required for testing (check the above "To test" section). The process will create a .coverage file in the project directory.

  5. If you have PyCharm Professional instead of PyCharm Community, you should also do this:

Ctrl + Alt + F6 (Choose coverage suite to display) -> + -> select any of the created files -> Show selected. This will add fancy colors in your scripts, depending on where the code is covered by tests.