pytest-django

invoking test case with in another test case in pytest framework

爷,独闯天下 提交于 2021-02-08 05:08:49
问题 I am using pytest for automation. Is there any option in pytest to invoking test case with in another test case. 回答1: Sure you can. With pytest, a test case is a simple function or method. For example: def test_foo(): assert 2 + 2 == 4 def test_bar(): assert [1] + [2] == [1, 2] test_foo() Consider why you would want to do this. Typically, keeping tests decoupled provides benefits, like easier debugging when a test fails. 来源: https://stackoverflow.com/questions/45210365/invoking-test-case-with

invoking test case with in another test case in pytest framework

时光总嘲笑我的痴心妄想 提交于 2021-02-08 05:08:33
问题 I am using pytest for automation. Is there any option in pytest to invoking test case with in another test case. 回答1: Sure you can. With pytest, a test case is a simple function or method. For example: def test_foo(): assert 2 + 2 == 4 def test_bar(): assert [1] + [2] == [1, 2] test_foo() Consider why you would want to do this. Typically, keeping tests decoupled provides benefits, like easier debugging when a test fails. 来源: https://stackoverflow.com/questions/45210365/invoking-test-case-with

How to show warnings in py.test

独自空忆成欢 提交于 2021-02-07 11:14:01
问题 I just ran py.test on my code and got the following output: ================== 6 passed, 2 pytest-warnings in 40.79 seconds ======================= However, I cannot see what py.test would like to warn me about. How can I turn on warning output to the console? py.test --help offers me the --strict flag: --strict run pytest in strict mode, warnings become errors. However I just want to see the output, not make my tests fail. I checked pytest.org and this question but they are only concerned

“Apps aren't loaded yet” when trying to run pytest-django

ぃ、小莉子 提交于 2021-01-27 02:10:45
问题 Using the (partial) polls app from the Django tutorial as an example, I'm trying to get pytest-django to run. Using the command django-admin startproject mysite2 , I've created a project directory with the following structure: . ├── db.sqlite3 ├── manage.py ├── mysite2 │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── polls │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ ├── 0001_initial.py │ │ └── __init__.py │ ├── models.py │ ├── tests.py │ ├── urls.py

pytest assert message customization with variable introspection

a 夏天 提交于 2020-02-20 07:35:29
问题 In the pytest documentation it says that you can customize the output message when an assert fails. I want to customize the assert message when testing a REST API method it returns an invalid status code: def test_api_call(self, client): response = client.get(reverse('api:my_api_call')) assert response.status_code == 200 So I tried to put a piece of code like this in conftest.py def pytest_assertrepr_compare(op, left, right): if isinstance(left, rest_framework.response.Response): return left

Why are most of my project's Django files missing from the PyTest Coverage report?

霸气de小男生 提交于 2020-01-16 16:47:40
问题 I'm running pytest-cov and pytest-django using tox . I have a very simple tox.ini file with limited omit files. The problem is when I run pytest using tox -e unit , I get a limited Coverage report: ---------- coverage: platform darwin, python 3.7.4-final-0 ----------- Name Stmts Miss Cover Missing ---------------------------------------------------------------------------- components/__init__.py 0 0 100% components/client/__init__.py 0 0 100% components/client/admin.py 27 0 100% components

How to test redirection in Django using pytest?

淺唱寂寞╮ 提交于 2020-01-14 10:16:31
问题 I already know that one can implement a class that inherits from SimpleTestCase , and one can test redirection by: SimpleTestCase.assertRedirects(response, expected_url, status_code=302, target_status_code=200, host=None, msg_prefix='', fetch_redirect_response=True) However, I am wondering what is the way I can check for redirection using pytest: @pytest.mark.django_db def test_redirection_to_home_when_group_does_not_exist(create_social_user): """Some docstring defining what the test is