Discover how one file can save you hours of repetitive test setup work!
Why Conftest for shared fixtures in Selenium Python? - Purpose & Use Cases
Imagine you are testing a website with many test files. Each test needs to open a browser, log in, and set up data. You write the same setup code in every test file.
This manual way is slow and tiring. If you change the setup, you must update every test file. It is easy to forget one place, causing errors and wasted time.
Using conftest.py for shared fixtures lets you write setup code once. All tests can use it automatically. This keeps tests clean, easy to update, and faster to write.
from selenium import webdriver def test_login(): driver = webdriver.Chrome() driver.get('url') # login steps # test steps driver.quit()
import pytest from selenium import webdriver @pytest.fixture def browser(): driver = webdriver.Chrome() yield driver driver.quit() def test_login(browser): browser.get('url') # login steps # test steps
It enables writing clean, reusable test setups that save time and reduce mistakes across many tests.
When testing an online store, you can use a shared fixture to open the browser and log in once. All tests for adding items, checking out, or searching use the same setup without repeating code.
Manual setup in every test file is slow and error-prone.
Conftest.py lets you share fixtures across tests easily.
This makes tests cleaner, faster to write, and easier to maintain.