15

I recently discovered the feature "Go To --> Test" in PyCharm.

If I choose "Create New Test", then the target directory of the new python file is wrong.

PyCharm wants to create the new python file in the same directory.

Up to now I use this structure:

src/myapp/setup.py
src/myapp/myapp/real_code.py
src/myapp/myapp/tests/test_real_code.py

How can I tell PyCharm to create test_real_code.py in above location?

Update

I created a feature request: https://youtrack.jetbrains.com/issue/JT-53069

Just for the records, here are docs about common test layouts: https://docs.pytest.org/en/latest/goodpractices.html#choosing-a-test-layout-import-rules

1 Answer 1

5
+50

In PyCharm Pro 2019.1.2, after clicking on Go To -> Test -> Create New Test... one can modify the target directory (first box of the pop up box that appears) as long as this directory already exists. The name of the file and of the method can also be changed there.

enter image description here

If a test for the function already exists, even outside the directory, it finds it and proposes to go there when one clicks on Go To -> Test

Sign up to request clarification or add additional context in comments.

2 Comments

If I understood it correctly, then I need to modify the target directory every time I create a new test. That's better than nothing. But is there no way to define a pattern for the target directory?
Yes, this is not super practical but as you say, better than nothing. I use the same test structure as you and has been digging into the settings to find a way to define this pattern without success...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.