microsoft / playwright-pytest

Pytest plugin to write end-to-end browser tests with Playwright.
https://playwright.dev/python/docs/test-runners
Apache License 2.0
425 stars 70 forks source link

Playwright starts browser in headed mode when called from VS Code Debugger - even on headless server #122

Open pearzt opened 2 years ago

pearzt commented 2 years ago

The current implementation starts the browser in headed mode automatically, if pytest is invoked from VS Code's debugger.

https://github.com/microsoft/playwright-pytest/blob/68bd92a133eeac597da61a0819768a589dafd6dd/pytest_playwright/pytest_playwright.py#L118-L120

While I get the idea behind this, it does not take remote development on a headless server into account. If $DISPLAY is not set, the test run naturally fails and leaves the user wondering why this happens because he did not provide --headed (e.g. in VS Code's python.testing.pytestArgs configuration). IMHO, the implementation should be changed to check for $DISPLAY at least.

Sparrow0hawk commented 1 year ago

Had this issue today when using VSCode Python Extension (v2023.14.0) Test debugger in WSL2.

Worked around it by changing the above setting but be great to know if this could be more configurable.

mxschmitt commented 1 year ago

Happy to accept patches about this to include an if with something like:

no_supported_display = sys.platform == "linux" and os.getenv("DISPLAY")
elif VSCODE_PYTHON_EXTENSION_ID in sys.argv[0] and _is_debugger_attached() and not no_supported_display`: 

(just put it quickly there, might need different conditions etc)