playwright-pytest
playwright-pytest copied to clipboard
[FEATURE] Config file support
Same thing as in js/ts world playwright.config.ts equivalent for python playwright.conf.py which would automatically parameterize all the tests.
Includes https://github.com/microsoft/playwright-pytest/issues/67
@mxschmitt
How about using the pyproject.toml file for configuration.
[tool.playwright]
headed = true
@pytest.fixture(scope="session")
def playwright_config(request: pytest.FixtureRequest) -> Dict:
rootpath = request.config.rootpath
config_file_path = rootpath / "pyproject.toml"
if not config_file_path.exists():
return {}
with config_file_path.open(mode="rb") as f:
config = tomli.load(f)
return config.get("tool", {}).get("playwright", {})
@pytest.fixture(scope="session")
def browser_type_launch_args(pytestconfig: Any, playwright_config: Dict) -> Dict:
launch_options = {}
headed_option = pytestconfig.getoption("--headed") or playwright_config.get("headed")
I am not a seasoned python developer. If this is an acceptable approach, I can open up a PR.
Pytest provides a way to add ini options to the config and read them:
- https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.Parser.addini
- https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.Config.getini