All subjects

Programming · Interview subject

Python Interview Questions

pytest fixtures, markers, parametrize and requests-based API tests.

54 questions

Quick interview answer

conftest.py fixtures for driver/session scope, page objects as classes, markers for suites, parametrize for data driving, requests or Playwright for the transport, and pytest-html or Allure for reports.

Detailed explanation

Fixtures replace setup/teardown and compose by scope (session for browser, function for page). Markers (@pytest.mark.smoke) select suites in CI, and @pytest.mark.parametrize drives data. Keep config in pytest.ini plus env vars, use requests.Session for API tests, and run in parallel with pytest-xdist once fixtures are properly scoped.

python
1@pytest.fixture(scope="session")
2def api():
3 s = requests.Session()
4 s.headers.update({"Authorization": f"Bearer {token()}"})
5 yield s
6 s.close()
7
8@pytest.mark.parametrize("status", ["NEW", "PAID"])
9def test_orders_by_status(api, status):
10 r = api.get(f"/orders?status={status}")
11 assert r.status_code == 200

Real-world example

A pytest + requests suite covering 90 endpoints ran in under two minutes with xdist.

Interview tip

Talk about fixture scope — it is the pytest equivalent of thread safety questions.

Next subjectSQL