问题描述
这是我与 core/tests.py
一起使用的 pytest-django
:
import pytest
def test_no_db():
pass
def test_with_db(db):
pass
似乎设置注入 db 需要 66 秒。测试开始时,收集几乎是即时的,然后是 66 秒的暂停,然后测试快速运行。
如果我禁用第二个测试,整个测试套件将在 0.002 秒内运行。 数据库在 Postgresql 上运行。
我是这样运行测试的:
$ pytest -v --noconftest core/tests.py
================================================================================ test session starts ================================================================================
platform linux -- Python 3.8.6,pytest-6.2.4,py-1.10.0,pluggy-0.13.1 -- /home/mslinn/venv/aw/bin/python
cachedir: .pytest_cache
django: settings: main.settings.test (from ini)
rootdir: /var/work/ancientWarmth/ancientWarmth,configfile: pytest.ini
plugins: timer-0.0.11,django-4.4.0,Faker-8.0.0
collected 2 items
core/tests.py::test_with_db PASSED [50%]
core/tests.py::test_no_db PASSED [100%]
=================================================================================== pytest-timer ====================================================================================
[success] 61.18% core/tests.py::test_with_db: 0.0003s
[success] 38.82% core/tests.py::test_no_db: 0.0002s
====================================================================== 2 passed,0 skipped in 68.04s (0:01:08) ======================================================================
pytest.ini
:
[pytest]
DJANGO_SETTINGS_MODULE = main.settings.test
FAIL_INVALID_TEMPLATE_VARS = True
filterwarnings = ignore::django.utils.deprecation.Removedindjango40Warning
python_files = tests.py test_*.py *_tests.py
为什么会这样?我能做什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)