Test fixtures provide reusable test data and configuration across the test suite. All fixtures are defined in conftest.py and are automatically available to all test files.
Loads test user data from testData/users.json and returns it as a dictionary. This fixture is session-scoped, meaning the JSON file is loaded once per test session for optimal performance.Scope:sessionSource:/workspace/source/tests/conftest.py:8
def test_login_with_valid_user(users): """Test login using data from users fixture""" username = users["valid_user"]["username"] password = users["valid_user"]["password"] # Use credentials in your test login_page.login(username, password) assert dashboard.is_displayed()def test_user_data_loaded(users): """Verify users fixture provides expected data""" assert "valid_user" in users assert "invalid_user" in users
Provides authentication credentials loaded from environment variables (.env file). This fixture fails early with a clear error message if required environment variables are missing.Scope:sessionSource:/workspace/source/tests/conftest.py:22
You can combine multiple fixtures in a single test:
def test_compare_user_sources(users, creds): """Compare data from JSON and environment sources""" json_username = users["valid_user"]["username"] env_username = creds["valid_user"] # Both sources should provide valid credentials assert json_username is not None assert env_username is not None
All fixtures are defined in tests/conftest.py, making them automatically discoverable by pytest across the entire test suite. No imports are needed to use these fixtures.
Ensure sensitive credentials are never committed to version control. Always use .env files (added to .gitignore) or secure environment variable management.