Skip to content

fix: keep multi-browser parametrization when the page fixture is overridden#314

Open
cycsmail wants to merge 1 commit into
microsoft:mainfrom
cycsmail:fix/multi-browser-overridden-page-fixture
Open

fix: keep multi-browser parametrization when the page fixture is overridden#314
cycsmail wants to merge 1 commit into
microsoft:mainfrom
cycsmail:fix/multi-browser-overridden-page-fixture

Conversation

@cycsmail

Copy link
Copy Markdown

Summary

  • When a user overrides the page fixture (e.g. def page(page): yield page), some pytest versions drop browser_name from the fixture closure, so --browser chromium --browser firefox silently runs the test against only one browser instead of parametrizing it.
  • In pytest_generate_tests, if browser_name is absent but a browser-backed fixture (page, context, new_context, browser, browser_type) is requested, re-add browser_name to metafunc.fixturenames before parametrizing. It's a no-op when browser_name is already present (pytest 9) or when no browser fixture is used, so non-browser tests are untouched.
  • Applied to both the sync and asyncio plugins, with a regression test in each that collects test_a[chromium] and test_a[firefox] from an overridden page fixture.

Reverting the plugin change makes the new tests fail on pytest 8.3.5 (only test_a is collected), confirming they guard the regression. On pytest 9 the closure already keeps browser_name, so the tests pass there regardless.

Fixes #172

@cycsmail

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Can't run tests with multiple browsers when overriding page fixture

1 participant