"Empty test suite" by running Django tests with Pycharm (tests are discovered if they are run from the shell)

I'm having a hard time running Django tests using PyCharm . In the past, I've done this easily using a "running python config" in which I usedmanage.py

to run them, I was on OSX and used python 2.7, Django <= 1.7, Pycharm <= 4. Now I'm on Linux Mint, I'm using Python 3.4.3, Django 1.8.2 and Pycharm 4.5. I've always used virtualenv to manage my projects. Now running "manage.py test" from Pycharm no tests were found (it prints "Empty test suite"). But the tests do exist, and if I run the command from the shell, they run. So I really don't understand what's going on. I can actually run tests using the "hack" I created, but the problem is that Pycharm cannot connect to the process to allow breakpoints in the tests (which is one of the features I use the most!). the "hack" is as follows:

I created a python script with:

import subprocess


def main():
    subprocess.call('./venv_activator.sh', shell=True)


if __name__ == '__main__':
    main()

      

then a bash script ( venv_activator.sh

):

#!/usr/bin/env bash
source .ENV/bin/activate
python manage.py test myapp -p "*_tests.py" --noinput -v 2 --settings=settings.test

      

In practice, a python script is used to create a "python running configuration" for Pycharm, then it activates virtualenv and invokes the django test command.

ps: yes, I have enabled "Django support" in PyCharm (and I have configured a python interpreter under virtualenv)

+2


source to share


3 answers


The problem is that PyCharm does not apply this search pattern to test files (-p "* _tests.py"). This is a bug that has already been reported: https://youtrack.jetbrains.com/issue/PY-15869



The solution was to simply rename my files: P

+6


source


Using pycharm, you can run tests directly by creating a test configuration. Create a configuration using Run> Edit Configuration. Add configuration from Django tests, set virtual env path, working directory (path to manage.py), target module (e.g. complete_project or complete_project.app_name). Run the config, it will run tests from test.py from the appropriate module.



+2


source


In my case, it was because my test method names did not start with test

. Renamed them and PyCharm started to run them correctly.

0


source







All Articles