pytest

How to follow Django redirect using django-pytest?

早过忘川 提交于 2019-12-10 21:23:16
问题 In setting up a ArchiveIndexView in Django I am able to successfully display a list of items in a model by navigating to the page myself. When going to write the test in pytest to verify navigating to the page "checklist_GTD/archive/" succeeds, the test fails with the message: > assert response.status_code == 200 E assert 301 == 200 E + where 301 = <HttpResponsePermanentRedirect status_code=301, "text/html; charset=utf-8", url="/checklist_GTD/archive/">.status_code test_archive.py:4:

test isolation between pytest-hypothesis runs

瘦欲@ 提交于 2019-12-10 20:29:22
问题 I just migrated a pytest test suite from quickcheck to hypothesis . This worked quite well (and immediately uncovered some hidden edge case bugs), but one major difference I see is related to test isolation between the two property managers. quickcheck seems to simply run the test function multiple times with different parameter values, each time running my function-scoped fixtures. This also results in many more dots in pytest's output. hypothesis however seems to run only the body of the

Pytest Finalizers - order of execution

别等时光非礼了梦想. 提交于 2019-12-10 18:56:18
问题 I am writing py.test program, considering the following py.test fixture code: @pytest.fixture(scope="class") def my_fixture(request): def fin1(): print("fin1") request.addfinalizer(fin1) def fin2(): print("fin2") request.addfinalizer(fin2) What the execution order? I didn't find any mentions on the documentation regarding the execution order of finalizers. Thanks in advance. 回答1: I guess the easiest way would be to just try running your code with -s and see in which order the prints happen.

Execute code if a test fails with py.test

家住魔仙堡 提交于 2019-12-10 18:34:32
问题 I'm doing UI test automation on Android using Appium and py.test. I'd like to be able to save a bug report using adb after a test fails. Is there a way to tell if a test fails in my test code so I can then run save the bug report in the teardown? Originally, I was just going to save the bug report after each test, but it's a bit excessive adding 45 seconds to each test. 回答1: You can implement a pytest_runtest_logreport hook in your conftest.py like this: def pytest_runtest_logreport(report):

pytest - ModuleNotFoundError - python 3.6.4

本小妞迷上赌 提交于 2019-12-10 17:54:22
问题 I have a project with this layout: ├── MANIFEST.in ├── README.md ├── __init__.py ├── company │ ├── __init__.py │ ├── api │ │ ├── __init__.py │ │ ├── auth.py │ │ ├── debug.py │ │ ├── exceptions.py │ │ ├── reporting.py │ │ ├── rest.py │ │ ├── soap.py │ │ └── utils.py │ ├── jinjaEnvironment.py │ ├── sql │ │ ├── __init__.py │ │ ├── connection.py │ │ └── sql_helper.py │ └── templates │ ├── __init__.py │ ├── getUser.xml │ ├── rest_write_custom_field.xml │ └── setUser.xml ├── company.egg-info ├──

Testing regexes in Python using py.test

[亡魂溺海] 提交于 2019-12-10 17:12:14
问题 Regexes are still something of a dark art to me, but I think that's one of those things that just takes practice. As such, I'm more concerned with being able to produce py.test functions that show me where my regexes are failing. My current code is something like this: my_regex = re.compile("<this is where the magic (doesn't)? happen(s)?>") def test_my_regex(): tests = ["an easy test that I'm sure will pass", "a few things that may trip me up", "a really pathological, contrived example",

How to write correct test with pytest?

依然范特西╮ 提交于 2019-12-10 16:52:33
问题 I can write some unittests but have no idea how to write test about createAccount() which connect other functions together. createAccount() contains some steps in order: Validate Email Validate Password Check Password Match Instantiate new account object Every step has some test cases. So, my questions are: 1. How to write createAccount() test case ? Should I list all possible combination test cases then test them. For example: TestCase0. Email is invalid TestCase1. App stops after retrying

py.test passing results of one test to another

时光毁灭记忆、已成空白 提交于 2019-12-10 16:06:33
问题 Currently I have test looking like this: @pytest.mark.parametrize("param", [1,2,3]) def test_two_services(param): id = check_service_one(param) check_service_two(id) Is there any way to split this test in two, where a second test depends on a first? 回答1: Remember to test at the boundary. So if the the values of id depend solely on param and if id isn't some implementation detail, but a part of the defined behaviour of the system under test, split up your tests like so: def test_service_one

using pytest --collect-only to only return individual test names

自古美人都是妖i 提交于 2019-12-10 15:29:03
问题 I am trying to sort out how to get a list of just the test names from a test file using pytest I have made it this far: $ pytest --collect-only my_test_file.py ============================================================================================= test session starts ============================================================================================== platform darwin -- Python 3.6.4, pytest-3.2.5, py-1.5.2, pluggy-0.4.0 rootdir: /Users/.../automation, inifile: plugins: xdist-1

pytest monkeypatch.setattr() inside of test class method

为君一笑 提交于 2019-12-10 15:27:24
问题 I have a test class with few test methods and I want to patch some app classes and methods from the test methods. In pytest docs I found an example of how to use monkeypatch module for tests. It that example all tests are just functions, not testclass methods. But I have a class with test methods: class MyTest(TestCase): def setUp(): pass def test_classmethod(self, monkeypatch): # here I want to use monkeypatch.setattr() pass And just passing monkeypatch as method param is obviously doesn't