microsoft / microsoft/playwright-pytest

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

Open
#172 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue p3-collecting-feedback
Dominant language
Python
Stars
563
Forks
90
Avg merge
11m
Merged PRs (30d)
1

Description

Context:

  • Playwright Version: 1.34.0 (pytest-playwright: 0.3.3)
  • Operating System: Linux
  • Python version: 3.11
  • Browser: All

Code Snippet

Just a simple test that overrides the page fixture.

import pytest


@pytest.fixture
def page(page):
    # do something with the page
    yield page


def test(page):
    assert True

Describe the bug

When running the above test file with pytest --browser firefox --browser chromium only one instance of the test is run and the following warning is given out instead:

pytest_playwright/pytest_playwright.py:326: UserWarning: When using unittest.TestCase specifying multiple browsers is not supported

When I include some other playwright fixture in either the page fixture or the test method, the test is run with the specified browsers as expected.

So for example, this works:

def test(page, browser_name):  # another playwright fixture
    assert True

But this does not:

def test(page, monkeypatch):  # a pytest fixture
    assert True

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with pytest --browser firefox --browser chromium using the overriding page fixture, then inspect pytest_playwright/pytest_playwright.py around line 326. Compare the fixture-only case with a test that includes browser_name and verify that the overridden page fixture runs once per requested browser without the unittest.TestCase warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.