How to correctly jump to source from PyCharm pytest test explorer?

188 Views Asked by At

I tried to jump to a file shown in pytest text explorer by double clicking on the name of a test function in the tree view of the test explorer (I use PyCharm 2023.1.1, Community Edition):

enter image description here

However, instead of opening the corresponding file in the editor:

{project_root}/back_end/test/test_fuel_split.py

PyCharm jumps to a wrong location:

External Libraries => Python 3.10.5 => Lib => test

How can I fix that? Is there some PyCharm or pytest configuration I need to adapt? Or is this a PyCharm bug?

2

There are 2 best solutions below

2
defsprite On

You will need to mark the tests folder as test sources in PyCharm in Preferences > Project Structure. They should appear green in the project explorer once this is configured correctly.

0
ttenev On

What worked for me was to set a working directory in the pytest configration template to the places where my automation is located. Clear all previous configs add the directory and run again the test: Pytest config template