“空测试套件";通过使用Pycharm运行Django测试(如果从外壳启动,则会找到测试) [英] "Empty test suite" by running Django tests with Pycharm (tests are found if launched from the shell)
问题描述
我很难尝试使用 PyCharm 运行我的 Django 测试.我过去使用"python运行配置"轻松地完成了该操作,其中使用了 manage.py
来运行它们,当时我在OSX上并使用python 2.7,Django< = 1.7,Pycharm<= 4.现在我在Linux Mint上,我使用Python 3.4.3,Django 1.8.2和Pycharm 4.5.我一直使用virtualenv来管理我的项目.现在,通过从Pycharm运行"manage.py测试",未找到任何测试(打印空测试套件").但是测试存在,并且如果我从外壳运行命令,它们就会被执行.所以我真的不明白发生了什么.实际上,我可以使用我创建的"hack"来启动测试,但是问题是Pycharm无法附加到进程中以允许测试中出现断点(这是我最常使用的功能之一!).我的"hack"如下:
I'm having an hard time trying to run my Django tests using PyCharm.
I did it easily in the past using a "python running configuration" in which I used manage.py
to run them, I was on OSX and using python 2.7, Django <= 1.7, Pycharm <= 4.
Now I'm on Linux Mint, I use Python 3.4.3, Django 1.8.2 and Pycharm 4.5.
I always used virtualenv to manage my projects.
Now by running "manage.py test" from Pycharm no tests are found (it prints "Empty test suite").
But tests exist, and if I run the command from the shell they get executed.
So I really don't understand what's going on.
I'm actually able to launch tests using "an hack" I created, but the problem is that Pycharm is not able to attach to the process in order to allow breakpoints in tests (which is one of the features I use the most!).
My "hack" is the following:
我用以下命令创建了一个python脚本
I created a python script with:
import subprocess
def main():
subprocess.call('./venv_activator.sh', shell=True)
if __name__ == '__main__':
main()
然后是bash脚本( venv_activator.sh
):
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
在实践中,python脚本用于为Pycharm创建"python运行配置",然后激活virtualenv并调用django test命令.
In practice the python script is used to create a "python running configuration" for Pycharm, then it activate the virtualenv and invokes the django test command.
ps:是的,我在PyCharm中启用了"Django支持"(并且我在virtualenv下配置了python解释器)
ps: yes, I turned on "Django support" in PyCharm (and I configured the python interpreter under the virtualenv)
推荐答案
问题是PyCharm不会将给定的搜索模式应用于测试文件(-p"* _tests.py").这是一个已报告的错误: https://youtrack.jetbrains.com/issue/PY-15869
The problem is that PyCharm doesn't apply the given search pattern for test files (-p "*_tests.py"). It's a bug that has already been reported: https://youtrack.jetbrains.com/issue/PY-15869
解决方案是简单地重命名我的文件:P
The solution has been to simply rename my files :P
这篇关于“空测试套件";通过使用Pycharm运行Django测试(如果从外壳启动,则会找到测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!