Configure PyCharm so that "Run Test" works

Currently "Run Test" (the green play button by each test)

triggers

/Users/dario.figueira/miniconda3/envs/decant_imaging/bin/python /Users/dario.figueira/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/231.8109.197/PyCharm.app/Contents/plugins/python/helpers/pycharm/_jb_pytest_runner.py -- /Users/dario.figueira/miniconda3/envs/decant_imaging/lib/python3.8/test/__init__.py:: 
Testing started at 14:26 ...
Launching pytest with arguments /Users/dario.figueira/miniconda3/envs/decant_imaging/lib/python3.8/test/__init__.py:: --no-header --no-summary -q in /Users/dario.figueira/Work/decant_imaging


============================= test session starts ==============================
collecting ... collected 0 items

============================ no tests ran in 0.01s =============================
ERROR: not found: /Users/dario.figueira/miniconda3/envs/decant_imaging/lib/python3.8/test/__init__.py::
(no name '/Users/dario.figueira/miniconda3/envs/decant_imaging/lib/python3.8/test/__init__.py::' in any of [<Package test>])


Process finished with exit code 4

Empty suite

Instead of actually running the test.

 

Workaround: "Edit configurations..."

and setting "Target:" to "Module name", and paste in the module name

 

 

How to make it so just clicking the green arrow Run Test will work for any test?

2
18 comments
Hi, is it possible to provide a project sample where the issue can be reproduced?
0

Hi Andrey Resler

Here https://github.com/WurmD/MWE-tests 

1. Set Default test runner to pytest

2. Right click the green arrow besides `def test_string_produced():` 

yields:

/Users/dario.figueira/miniconda3/envs/MWE-tests/bin/python /Users/dario.figueira/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/231.8109.197/PyCharm.app/Contents/plugins/python/helpers/pycharm/_jb_pytest_runner.py -- /Users/dario.figueira/miniconda3/envs/MWE-tests/lib/python3.10/test/__init__.py:: 
Testing started at 16:53 ...
Launching pytest with arguments /Users/dario.figueira/miniconda3/envs/MWE-tests/lib/python3.10/test/__init__.py:: --no-header --no-summary -q in /Users/dario.figueira/Work/MWE-tests

============================= test session starts ==============================
collecting ... collected 0 items

============================ no tests ran in 0.01s =============================
ERROR: not found: /Users/dario.figueira/miniconda3/envs/MWE-tests/lib/python3.10/test/__init__.py::
(no name '/Users/dario.figueira/miniconda3/envs/MWE-tests/lib/python3.10/test/__init__.py::' in any of [<Package test>])


Process finished with exit code 4

Empty suite

0

Thank you,

The sample works for me out of the box. Do you have these checkboxes enabled in your run/debug configuration?

0

Yes

and it is also set in the template

To be doubly sure Andrey Resler, you clicked *this* green play button, and the test ran?

0
Yes, I'm clicking the gutter icon "play". 

Actually, PyCharm should create a temporary configuration with module path automatically. Are you using the latest PyCharm version by any chance? 

https://www.jetbrains.com/pycharm/download/

If the issue is reproduced in the latest version, please also go to **Preferences | Tools | Python Integrated Tools** and try setting default test runner to pytest.

Does it help?
0

Now in latest version

PyCharm 2023.1 (Professional Edition)
Build #PY-231.8109.197, built on March 29, 2023
Licensed to Ocado Innovation Ltd

Runtime version: 17.0.6+10-b829.5 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.3.1
GC: G1 Young Generation, G1 Old Generation
Memory: 6144M
Cores: 16
Metal Rendering is ON

Clicking the gutter icon "play" yields the same faulty behaviour

Default test runner was already set to pytest

 

0
Could you try with the default IDE settings?

To restore default settings, you can use **File | Manage IDE settings | Restore Default Settings...**. Your current settings will be backed up, so you can revert to them later if needed (to do this, just import settings from the backed up folder).
0

:confused:

With Default Settings my PyCharm is in a broken state:

it does not analyse the files, it's continuously starting analysing and stopping 

the little circling activity icon keeps appearing and disappearing

And thus, since it doesn't analyse, the gutter icon "play" does not show up.

What now?

0
Restoring default settings nukes the interpreter configuration. Please reconfigure the interpreter.

https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html
0

Nop :( same behavior with Default Configurations

0

So you can't reproduce, and the issue persists with default configurations here and default test runner set to pytest

Is this a Mac issue? Can you test with a Mac?

0

Hi! 

Are there any updates on this issue? I just got exactly the same problem when I upgraded PyCharm from version 2023.2.2 to 2023.3.3. I'm also using MacOs. 

0

What's happening? We're paying, why are we not getting support?

Support, would you please test in a Mac?

0
Can I ask you to submit a support ticket to [support](https://intellij-support.jetbrains.com/hc/en-us/?pycharm) and provide logs from **Help | Collect Logs and Diagnostic Data**?
0

I managed to solve the issue by marking the test folder as “Test” and the source folder as “Source” in Settings -> Project -> Project Structure. It seems that when you have a directory in “Source” with the same name as a directory in “Tests”, the run configuration chooses the wrong directory for the tests if you don't explicitly set the test-source distinction.

1

What should I see here?

Should the `src` folder be automatically assigned to “Sources”, and `test` be automatically assigned to “Tests”?

0

So first you select your “test” directory on your tree structure and then click on the button “Tests” on the upper bar that says “Mark as:”. Do a similar process with the “src” directory marking it as “Sources”. This was apparently not set up automatically.

0

Assigning `src` folder to “Sources”, and `test` to “Tests” solved it for me

0

Please sign in to leave a comment.