PyCharm中运行pytest出现空测试套件问题求助
Troubleshooting PyCharm 2017.3.2 pytest Execution Issue
Let's break down and fix the problem you're facing when running pytest in PyCharm. First, let's recap your setup to make sure we're aligned:
Your Setup Details
- Test file path:
C:\Temp\agents_automation_2\x_tests.py - Test code:
import pytest def test_mytest(): assert False
- Partial run output:
C:\Python36-32\python.exe "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pycharm\_jb_pytest_runner.py" --path C:/Temp/agents_automation_2 Launching py.test with arguments C:/Temp/agents_automation_2 in C:\Temp\agents_automation_2...
It looks like PyCharm is initiating the pytest runner, but not completing the test execution or showing results. Here are the most likely fixes, ordered by simplicity:
1. Run the Test File Directly (Not Just the Directory)
Instead of running the entire agents_automation_2 directory, try targeting the specific test file directly:
- Right-click on
x_tests.pyin PyCharm's project explorer - Select Run 'pytest in x_tests.py'
This tells PyCharm to create a dedicated configuration for that file, eliminating ambiguity about which tests to execute.
2. Verify Your PyTest Run Configuration
If the above doesn't work, double-check your run configuration settings:
- Click the run dropdown in the top-right of PyCharm → Select Edit Configurations...
- If you don't have an existing pytest config, click the
+button and choose pytest - For the Target field, select Script path and browse to your
x_tests.pyfile - Confirm the Python interpreter is set to
C:\Python36-32\python.exe(the environment you intend to use) - Save the configuration and run it again
3. Ensure pytest is Installed in Your Target Interpreter
It's possible the Python interpreter PyCharm is using doesn't have pytest installed. Let's fix that:
- Open PyCharm's built-in Terminal
- Run this command to install a PyCharm 2017.3.2-compatible pytest version:
(Newer pytest versions aren't fully supported by older PyCharm releases like 2017.3.2)C:\Python36-32\python.exe -m pip install pytest==4.6.11 - Test if pytest works outside PyCharm first by running:
You should see the assertion failure output here. If this works, the issue was simply missing pytest in the selected interpreter.cd C:\Temp\agents_automation_2 C:\Python36-32\python.exe -m pytest x_tests.py -v
4. Enable the PyTest Plugin in PyCharm
Older PyCharm versions sometimes disable plugins by default:
- Go to File → Settings → Plugins
- Search for pytest in the plugin list
- Make sure the checkbox next to it is checked
- Restart PyCharm to apply the change
内容的提问来源于stack exchange,提问作者David Fliguer
相关产品推荐
相关产品推荐

