pytest-django[14] 虽然 Django 内置了测试工具,但 pytest 和 pytest-django 插件在社区中被广泛使用。 django-q2: https://github.com/django-q2/django-q2 [13] Wagtail CMS: https://github.com/wagtail/wagtail [14] pytest-django : https://github.com/pytest-dev/pytest-django [15] pytest-cov: https://github.com/pytest-dev/pytest-cov
• 核心组件:Model、Admin、Authentication、Migrations、Views、management命令行、Forms、Template • 测试框架:pytest(42%)、pytest-django
下面是一些流行插件的注释列表: pytest-django: 编写测试 django 应用程序,使用pytest集成。
下面我们看一下一些常用的插件及介绍: pytest-django: 为django应用编写测试,使用pytest集成 Pytest-twisted: 为twisted应用编写测试 Pytest-cov:
添加一个配置文件 具体看pytest-django官网 (opens new window) [pytest] DJANGO_SETTINGS_MODULE=event_track_root.settings
pytest-django[4]插件提供了一个django_db标记。任何没有这个标记的测试在试图访问数据库时都会失败。第一个试图访问数据库的测试将触发Django测试数据库的创建。 pytest-django pytest-django[9]为处理Django测试提供了一些有用的fixtures 和 marks。 https://www.djangoproject.com/ [3] monkeypatch: https://docs.pytest.org/en/latest/monkeypatch.html [4] pytest-django : https://coverage.readthedocs.io/ [8] pytest-cov: https://pytest-cov.readthedocs.io/en/latest/ [9] pytest-django
使用数据库事务(如 Python 的 pytest-django 插件)在测试后自动回滚数据。数据驱动测试通过参数化覆盖多种场景(如正常值、边界值、异常值)。
1.4.1 pyrsistent 0.16.0 pytest 5.3.5 pytest-django
事务管理通过事务回滚(如pytest-django的transactional_db)自动清理数据。
此外,它还拥有广泛的社区支持,这让您可以访问很多扩展,比如pytest-django,它可以帮助您为Django web应用程序集成编写测试。
还好 pytest-django 实现了等效的功能。 我们快速升级到了 pytest-django 4.4 版,准备就绪: def test_should_send_notification( db, mailoutbox, django_capture_on_commit_callbacks
Pytest-django : 开发web Pytest-selenium : pytest提供运行支持selenium为基础 allure报告 这个展现的测试报告比较全面,也做的比较好,官网,python
例如,使用pytest-django插件可以方便地集成Django应用程序的测试,并提供更多的功能和选项来定制测试行为。
https://github.com/cosmicpython/code.git cd code git checkout appendix_django 使用 Django 的存储库模式 我们使用了一个名为pytest-django ② pytest-django mark.django_db(transaction=True) 是必须的,用于测试我们的自定义事务/回滚行为。 由于 Django 与数据库紧密耦合,您必须使用诸如pytest-django之类的辅助工具,并从代码的第一行开始仔细考虑测试数据库的使用方式,这是我们在纯领域模型开始时不必考虑的。
pytest-django, star:308 - pytest 的一个 Django 插件。 splinter, star:1355 - Web 应用的一个 Python 测试框架。