Django project: "Run Test" incorrect paths in PyCharm

In my Django project, the project structure is

foo
  doc
  src
     bar
        app1
            test_models.py
        app2
            test_models.py


When I right-click on a unit test function (for instance App1Test.test_app) inside the test_models.py file, the "run test" item in the menu says "Run 'Test src.bar.app1.test_models.App1Test.test_app'" and when I execute that I get "ImportError: No module named src".

I have to then edit the configuration (in the toolbar) and manually edit the path (i.e. remove the "src.bar" bit) and run the test for it to work.

Is there anywhere in PyCharm where I can set the path up correctly so it doesn't add the "src.bar" bit?

"bar" is my "Sources Root", so I'm surprised that it adds the directories above "bar" to the path.

Any help much appreciated!

Thanks
Patrick
5 comments
Comment actions Permalink
This is also an issue when re-running failed tests, as it will try running them with the incorrect path
0
Comment actions Permalink
This has been bugging me for months, but I haven't taken the time to boil down a minimal test-case for it.
I was hoping it would go away in PyCharm 4.0, but no such luck. :(
0
Comment actions Permalink
I've gone through pretty much every setting, no luck.

The only "fix" I found was to exclude the higher directories from the PyCharm project, but since I want to be able to edit files in those directories in PyCharm that's not a solution...

Would be great if someone at JetBrains could give some insight! Thanks!
0
Comment actions Permalink
Unfortunately I don't see JetBrains participate in this forum very much. I've had better luck with the bug tracker – and this is definitely a bug.
0
Comment actions Permalink
I've added a issue to the bug tracker:
https://youtrack.jetbrains.com/issue/PY-14677

Let's see if it gets fixed!
0

Please sign in to leave a comment.