Manuals / Playwright with Python / Chapter 20

Part 3 · Test Structure & Framework · intermediate · ~40 min · Chapter 20 of 61

13. Test Organization

Markers Markers tag tests so you can selectively run subsets instead of the entire suite every time. python import pytest @pytest.mark.smoke def test_login_works(): ...

Path progress
32%

Step 1 of 3

Overview

Markers Markers tag tests so you can selectively run subsets instead of the entire suite every time. python ... ... bash Custom markers need to be registered in pytest.ini (Chapter 15) or pytest will emit a warning about unknown markers. What it does: Attaches a tag to a test function, usable later to filter which tests run. Types/params: Pointers: Use consistent, small marker vocabulary across the team (smoke, regression, critical) rather than ad-hoc one-off tags — otherwise -m filtering becomes unreliable. Parametrized tests Instead of writing near-identical test functions for different inputs, parametrize one test function to run multiple times with different data. python ("", "validpass", "Username is required"), ("validuser", "", "Password is required"), ("validuser", "wrongpass", "Invalid credentials"), ]) This runs as three separate test cases in the report, each clearly showing which input combination passed/failed — far more maintainable than three nearly-identical copy-pasted test functions.

OverviewDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Page under testdrag · tap →Multi-browserdrag · tap →Automation pathdrag · tap →Tooling nodedrag · tap →
Was this step clear?
Chapter learning outcomes
  • Overview (2)

Clear these before you leave

Side quest

13. Test Organization deliverable

Apply one idea from “Overview” in a small script or note.