Module 4: Test Parametrization

# test_parametrize.py

import pytest

@pytest.mark.parametrize("x, y, expected_result", [(1, 2, 3), (3, 4, 7), (5, 6, 11)])
def test_addition(x, y, expected_result):
    assert x + y == expected_result
# test_fixture_parametrize.py

import pytest

@pytest.fixture(params=["chrome", "firefox"])
def browser(request):
    if request.param == "chrome":
        driver = webdriver.Chrome()
    elif request.param == "firefox":
        driver = webdriver.Firefox()
    yield driver
    driver.quit()

def test_google_search(browser):
    browser.get("https://www.google.com")
    assert "Google" in browser.title

Last updated