Category : fixtures

This seems like a very basic question, but I looked at https://docs.pytest.org/en/6.2.x/reference.html, which I think is the reference for pytest and couldn’t find the answer. So I wanted to combine a pytest.fixture (setup/teardown using yield) with a pytest.mark.parametrize … and I realised that they both have to be included as parameters in the test function. ..

Read more

I have a problems with fixtures’ scope in test class. I have 4 types of items: type1_old, type1_new, type2_old and type2_new. I want to start all test class functions for one type of item. At begin for type1_new then type1_old then type2_new then type2_old. Now tests run like: test_1.py::TestDifferentFixtures::test_1[item_1_type1_new_no_3d] PASSED [ 6%] test_1.py::TestDifferentFixtures::test_1[item_2_type1_old_no_3d] PASSED [ ..

Read more

Currently if test will fail from any reason the objects which were created in AWS service catalog(SC) can stay there after test is finished due all failed asserts stop script, so clean few lines after cant be invoked. Example of code: product_name,result=launchProduct(role, product, storagerole) logger.info("Creating pod with storagerole: {}".format(storagerole)) assert result, ‘Product ‘ + product ..

Read more

we have function called delete_product in assert which is called multiple times, how to remove all instances of delete_product and write one single function using pytest fixtures, code is below try: output = subprocess.check_output(cmd, shell=True).decode() except subprocess.CalledProcessError as error: logger.error("error: {}".format(error)) assert delete_product(role, product_name), ‘Product ‘ + product_name + ‘ could not be deleted by ..

Read more

I am using the below hook to print the time taken to run fixtures in pytest. @pytest.hookimpl(hookwrapper=True) def pytest_fixture_setup(fixturedef, request): start = time.time() yield end = time.time() print( f’Fixture setup: {fixturedef.argname}’ f’, request={request}’ f’, time={end – start}’ ) is it possible to collect all these execution time along with fixture name and print at the ..

Read more

I try to create a test case in pytest. I want to use parameterized fixtures to get parameters from the @pytest.mark.parametrize decorator and create more types of tests. My code looks right now: @pytest.mark.parametrize( "a", ["1", "2"], ids=["a:1", "a:2"] ) @pytest.mark.parametrize( # type: ignore "fixture_a", [{"b": 1}], ids=["b:1"], indirect=["fixture_a"], ) def test_postgres_basic(fixture_a, a): … What ..

Read more

I have a code as follwos in my test_myfunc.py @pytest.fixture def dummy_string_EN(): return ‘This is an English string.’ @pytest.fixture def dummy_string_DE(): return ‘Das hier ist Deutsch.’ @pytest.fixture def dummy_string_FR(): return ‘la maison blanche est tombée’ Then I would like to use some of those texts to check my functions: def test_load_language_models(dummy_string_EN): tee = myfunc(dummy_string_EN) assert ..

Read more

I want to test my code and I need to create some directories in it. I tried using: def test_something(pytester): pytester.makepyfile("foobar123") pytester.makepyfile(custom="foobar1234") print(pytester.path) But these files are created in the temporary directory. I need to create the files inside the test folder of the project, in a folder with a specific name (for example ‘test-output’). ..

Read more

I am trying to use the pytester fixture, to create some files in the test directory, but I get the following error: def test_something(pytester): E fixture ‘pytester’ not found > available fixtures: _configure_application, _monkeypatch_response_class, _push_request_context, accept_any, accept_json, accept_jsonp, accept_mimetype, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, class_mocker, client, client_class, config, cov, doctest_namespace, live_server, mock_sparql_endpoint, mocker, module_mocker, ..

Read more