12
votes

I'm having issues with running pytest tests from inside PyCharm

I have a file x_tests.py inside a folder called agents_automation_2 in C:\Temp, the content of the file is

import pytest
def test_mytest():
    assert  False

When I run I get the following 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 ============================= test session starts ============================= platform win32 -- Python 3.6.4, pytest-3.4.2, py-1.5.2, pluggy-0.6.0 rootdir: C:\Temp\agents_automation_2, inifile: plugins: xdist-1.22.0, forked-0.2 collected 0 items ======================== no tests ran in 0.01 seconds =========================

However, when I run from a regular windows command line inside the folder the test runs OK

Any idea of what might be the issue ?

Thanks !!!

4

4 Answers

10
votes

The name of your test file does not conform to a default pytest discovery rules. If you change x_tests.py to x_test.py it run the test and fails as expected. Take a look at this page for more info on pytest discovery rules.

0
votes

Make sure that PyCharm is configured to use PyTest. By default it uses unittests. Checkout this doc: https://www.jetbrains.com/help/pycharm/choosing-your-testing-framework.html. Once you've correctly configured PyCharm to use PyTest, when you, for example, open the context menu for the test file, you'll see something like Run 'PyTest in ... '

0
votes

In my case I had only to delete the pytest.ini file from the project.

0
votes

For those using WSL, problem might be related to WSL being unaccessible. If you are getting this error on WSL,

Logon failure: the user has not been granted the requested logon type at this computer.

Try restarting the vmcompute service in PowerShell (run as Administrator):

powershell restart-service vmcompute

Source: https://github.com/microsoft/WSL/issues/5401