playwright-pytest
playwright-pytest copied to clipboard
Playwright starts browser in headed mode when called from VS Code Debugger - even on headless server
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.
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.
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)