I am having a hard time trying to configure tests running in PyCharm.
I want to run tests for my custom django apps, so my configuration looks something like this:
It works okay mostly (tests run, succeed), though it doesn't let you re-run individual tests and re-run failed ones - it always runs all tests for specified applications (common and authorization).
The manual says I should put django application names in "Target" field like this:
But whenever I do it, my tests fail to run with weird errors: sometimes it cannot import some modules, though they are definitely accessible, sometimes there are a lot of NoReverseFound exceptions, though none of them are actually present in the code.
I suppose I am configuring something wrong, but I cannot understand what. I am running the latest version of PyCharm and one of the 1.5.x versions of Django (some legacy code from back in the day I had to maintain)
UPD: If I put authorization.UserApiTestCase.test_login
in target - it works great, authorization.UserApiTestCase
works too, but putting just appname (authorization
) won't work and will produce NoReversrMatch or import errors... leaving Target empty will work, too, though it will run even iinternal Django tests and that's not what I need - I just want to run all my apps' tests (or tests from specific apps).
If your project structure in PyCharm looks similar to this:
myproject
├── README.md
├── myproject
│ ├── app1
│ │ └── test.py
│ ├── app2
│ │ └── test.py
│ ├── app3
│ │ └── test.py
│ └── settings.py
└── requirements.txt
Then you may need to add the second level myproject
folder as a "Sources Root"
"Sources Root" folders are indicated by a blue folder icon in the "Project" window
To add a "Sources Root" go to Preferences -> Project:MyProject -> Project Structure
Also check off "add source roots to PYTHONPATH" in the "Run/Debug Configurations".
After that you should be able to run tests with specified targets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With