Python Can';t让Django运行简单的单元测试

Python Can';t让Django运行简单的单元测试,python,django,unit-testing,Python,Django,Unit Testing,我在一个名为testDummy.py的文件中得到了一个最小的测试用例,该文件位于/MyApp/MyApp/(与默认的设置.py一起) 当执行manage.py测试-v2时,我得到 Creating test database for alias 'default' ('test_myapp')... Creating tables ... Creating table django_content_type Creating table contenttypes_concretemodel ..

我在一个名为
testDummy.py
的文件中得到了一个最小的测试用例,该文件位于
/MyApp/MyApp/
(与默认的
设置.py一起)

当执行
manage.py测试-v2
时,我得到

Creating test database for alias 'default' ('test_myapp')...
Creating tables ...
Creating table django_content_type
Creating table contenttypes_concretemodel
...
Creating table myapp_login_audit
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
test_get_for_concrete_model (django.contrib.contenttypes.tests.ContentTypesTests) ... ok
...
test_shortcut_view (django.contrib.contenttypes.tests.ContentTypesTests) ... ok
test_shortcut_view_with_broken_get_absolute_url (django.contrib.contenttypes.tes
ts.ContentTypesTests) ... ok
test_shortcut_view_without_get_absolute_url (django.contrib.contenttypes.tests.C
ontentTypesTests) ... ok

----------------------------------------------------------------------
Ran 10 tests in 0.389s

OK
Destroying test database for alias 'default' ('test_myapp')...
但是,它总是运行相同的10个测试(没有一个是我的)。如果我执行
manage.py测试-v2myapp
,它将运行0个测试

我错过了什么


(Python3,Django 1.6)

您是否已将
MyApp
添加到已安装的应用程序中?IIRC,单元测试必须位于应用程序根目录中名为
tests.py
的文件中,才能由
manage.py test
获取。当您执行
manage.py startapp
时,会自动创建该文件。另请参阅。它包含在已安装的应用程序中-我相信我显示的第二个命令行应该会出错,如果不是的话@阿雅:谢谢你给我这些文件的链接,但我已经看过了。根据
测试发现基于unittest模块的内置测试发现。默认情况下,这将在当前工作目录下名为“test*.py”的任何文件中发现测试。
这正是我的目标。我将尝试
tests.py
@Basic好吧,您可能可以将测试脚本保留在原来的位置。根据文档,它在
tests.py
中提取所有类,这些类是
django.test.TestCase
的子类,因此您可以在
tests.py
中执行一系列导入操作,就像从somepackage.testDummy import*
中导入
一样。
Creating test database for alias 'default' ('test_myapp')...
Creating tables ...
Creating table django_content_type
Creating table contenttypes_concretemodel
...
Creating table myapp_login_audit
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
test_get_for_concrete_model (django.contrib.contenttypes.tests.ContentTypesTests) ... ok
...
test_shortcut_view (django.contrib.contenttypes.tests.ContentTypesTests) ... ok
test_shortcut_view_with_broken_get_absolute_url (django.contrib.contenttypes.tes
ts.ContentTypesTests) ... ok
test_shortcut_view_without_get_absolute_url (django.contrib.contenttypes.tests.C
ontentTypesTests) ... ok

----------------------------------------------------------------------
Ran 10 tests in 0.389s

OK
Destroying test database for alias 'default' ('test_myapp')...