Category : pytest

I have various test cases that use common data. I use pytest fixtures to cache test data and speed-up the test. For example: @pytest.fixture(scope=’module’) def data(): large_data = download(‘XYZ’) return large_data def test_foo(data): pass def test_bar(data): pass I would like to extend the test to two datasets. A brute-force solution is: @pytest.fixture(scope=’module’) def data1(): large_data ..

Read more

There is a function that is called inside the function under test (get_full_facebook_error_message) def get_full_facebook_error_message(e: Any) -> str: details = ” if isinstance(e.body(), dict): details = e.body().get(‘error’, {}).get(‘error_user_msg’, ”) return ‘{}. {}’.format(e.get_message(), details) How do I determine the custom value that the mock function returns ? Now in the body of the test it is ..

Read more

We use the pytest libray for automation test. We need to take screen shots for fail case. I want to use "mydriver" variable in "pytest_runtest_makereport" method. I want to take screen shots with this variable for fail case. Can you help me ? import time from appium import webdriver import pytest @pytest.yield_fixture(scope="function") def driver(): "Setup ..

Read more

So I have a lot of (pytest) test that test logs with the caplog fixture, probably not done in the best way (as I’m realizing now). I used a ot of statements like caplog.records[0] and caplog.records[-1] but now I need to log something in a function that is called a lot through out my project ..

Read more

I have a parametrized pytest test and use tuples as expected values If I run the tests these values are not displayed and autogenerated ones (expected1…expected) are shown in the report Is it possible to have tuple values in the output? Test sample: @pytest.mark.parametrize(‘test_input, expected’, [ (’12:00 AM’, (0, 0)), (’12:01 AM’, (0, 1)), (’11:59 ..

Read more