I'm trying to configure my IntelliJ Ultimate 2017 IDE to run Python unit tests. It's not working.
- The project is a Gradle project, and most modules are Java/Scala. There are several Python modules though.
- The Python plugin is installed and the Python facet added to the appropriate modules.
- The Python Interpreter is set up fine. The IDE can actually move around in the code with a ctrl-click action.
- Under 'Project Structure' -> '
<mymodule>' -> dependencies both the interpreter and the<Module source>are included. - Each Python module has a 'content root'. Immediately under this is a
srcfolder, under which there is atestfolder. The contents of the test folder mirror thesrcfolder, except that files are prepended withtest_to avoid Python name collisions. - The test configuration has both 'Add source/content roots to PYTHONPATH' options checked. The interpreter is specified.
- If
testis marked as a tests folder within the module settings, I can right click and 'run tests' for the tests in that folder. However,ImportErrors occur, because it can't find modules within thesrcdirectory. - There are
__init__.pyfiles in all the appropriate places. IntelliJ gives you what it is running, and if I run that on the command, it works, something like:
python -m unittest discover -s /Users/nathanielford/myrepo/mymodule/src/tests -p test_util.py
It appears as though the root path that is being used is set to wherever the unittest file I'm running is: it doesn't use src as the path, and so it cannot find things to import. There is no obvious place to specify this behavior. It didn't seem to work like this in the past.
This started happening recently, after an IntelliJ update. It's possible some configuration became screwy and needs to be fixed, but I don't know what that is. It's also possible that some bug was introduced into IntelliJ, but I don't know how to identify that, either. What am I missing?
