'unittests work from command line but not pycharm

I'm writing some unit tests that I'd like to debug in pycharm. Debugging works just fine. However, if I want to run the tests outside of debug mode, I get:

C:\Users\my_name\Miniconda3\envs\feature-extraction\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --path D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py

Testing started at 5:04 PM ...

Ran 1 test in 0.002s
Launching unittests with arguments python -m unittest D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py in D:/

FAILED (errors=1)

...
...
    module = __import__(module_name)
ModuleNotFoundError: No module named 'test_misc'

However, I am able to get them to run the tests in the command line with:

"C:\Users\my_name\Miniconda3\envs\feature-extraction\python.exe" "C:\Program Files\JetBrains\PyCharm Community Edition 2021.1.1\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --path D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py

OR this:

python -m unittest D:/projects/A2TD/feature_extraction/tests/reconstruction/test_misc.py

You will notice that both of the above commands are copied and pasted directly from the PyCharm run output where the error occurs.

These commands work when run from any location within the top level project.

I am using unittest with default run configurations which are automatically populated on first run, for example:

enter image description here

With a standard project structure like:

project_folder
|
|- top_level_package/
|   |
|   |- __init__.py
|   |- sub_packages/ (containing modules)
|   
|-tests/
    |- __init__.py
    |- package_to_test/
         |
         |- __init__.py
         |- test_module1.py
         |- test_module2.py

Question:

How do I get unit tests to run in PyCharm outside of debug mode? Obviously I could just run them in debug mode, but then I'd have to remove all of my breakpoints.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source