How to use resource_setup method in tempest

Best Python code snippet using tempest_python

06_pytest_user_fixtures.py

Source:06_pytest_user_fixtures.py Github

copy

Full Screen

...6import pytest7 8# Простая пользовательская фикстура - это функция с декоратором @pytest.fixture()9@pytest.fixture()10def resource_setup(request):11 print("Подготовка ресурсов")1213 def resource_teardown(): # <- Функция сброса окружения14 print("Освобождение ресурсов")15 request.addfinalizer(resource_teardown) # <- Добавление финализатора1617 18# По умолчанию, scope = "function", autouse=False19@pytest.fixture(scope="function", autouse=True)20def another_resource_setup_with_autouse(request):21 print("another_resource_setup_with_autouse")22 def resource_teardown():23 print("another_resource_teardown_with_autouse")24 request.addfinalizer(resource_teardown)2526# Фикстура может возвращать что-то в тест (объект/ресурс)27@pytest.fixture(scope="module")28def resource_setup(request):29 print("\n >> 'Подключение' к БД")30 db = {"Red":1, "Blue":2, "Green":3}31 def resource_teardown():32 print("\n >> 'Отключение' от БД")33 request.addfinalizer(resource_teardown)34 return db35 3637@pytest.yield_fixture()38def resource_setup_with_yield():39 print("resource_setup_with_yield")40 yield41 print("resource_teardown_with_yield")42 ...

Full Screen

Full Screen

test_2.py

Source:test_2.py Github

copy

Full Screen

1import pytest2def resource_teardown():3 print("\ndisconnect")4@pytest.fixture(scope='function') # scope - уровень(для ф-ции/ всех ф-ций в файле)5def resource_setup(request):6 print("\nconnect to conn")7 db = {"Red": 1, "Blue": 2, "Green": 3}8 request.addfinalizer(resource_teardown) # добавить выполнениие ф-ции после выполнения теста9 return db10def test_red(resource_setup):11 print(resource_setup) # то что возвращает ф-ция resource_setup12 assert resource_setup["Red"] == 113@pytest.mark.parametrize("x", [-1, 2])14@pytest.mark.parametrize("y", [-10, 11]) # параметризует аргументы тест-функции15def test_cross_params(x, y):16 print(f"x: {x} y:{y}") # при нескольких параметризациях будет декартово произведение параметров...

Full Screen

Full Screen

test_one.py

Source:test_one.py Github

copy

Full Screen

1import pytest2@pytest.fixture(scope="module")3def resource_setup(request):4 print("\nconnect to db")5 db = {"Red": 1, "Blue": 2, "Green": 3}6 def resource_teardown():7 print("\ndisconnect")8 request.addfinalizer(resource_teardown)9 return db10def test_db(resource_setup):11 for k in resource_setup.keys():12 print("color {0} has id {1}".format(k, resource_setup[k]))13def test_red(resource_setup):14 assert resource_setup["Red"] == 115def test_blue(resource_setup):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful