Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm: Create Test --> Target directory?

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

like image 741
guettli Avatar asked Jun 03 '19 11:06

guettli


People also ask

How do I set the default test runner in PyCharm?

To set a test runner, press Ctrl+Alt+S to open the IDE settings and select Tools | Python Integrated Tools, and then select the target test runner from the Default test runner list.

How do I run a test case in PyCharm?

PyCharm makes it easy to select just one test to run. In fact, there are several ways to do it: With the cursor anywhere in the test you want to focus on, right-click and choose to run that in the test runner. Right-click on the test in the test tool listing and choose to run it.

How do I create a gherkin in PyCharm?

In the Project tool window, right-click a directory, where feature files should be created. From the context menu of the target directory, choose New | Gherkin feature file, and specify the filename. In the feature file, type your scenario.


1 Answers

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

like image 89
Eskapp Avatar answered Nov 15 '22 12:11

Eskapp