Skip to content

Commit

Permalink
chore: launch the browser headed by default if debugger is attached (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Mar 16, 2022
1 parent 676a301 commit 456f828
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pytest_playwright/pytest_playwright.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import shutil
import os
import sys
import warnings
from typing import Any, Callable, Dict, Generator, List, Optional

Expand Down Expand Up @@ -105,12 +106,18 @@ def pytest_runtest_setup(item: Any) -> None:
pytest.skip("skipped for this browser: {}".format(browser_name))


VSCODE_PYTHON_EXTENSION_ID = "ms-python.python"


@pytest.fixture(scope="session")
def browser_type_launch_args(pytestconfig: Any) -> Dict:
launch_options = {}
headed_option = pytestconfig.getoption("--headed")
if headed_option:
launch_options["headless"] = False
elif VSCODE_PYTHON_EXTENSION_ID in sys.argv[0] and _is_debugger_attached():
# When the VSCode debugger is attached, then launch the browser headed by default
launch_options["headless"] = False
browser_channel_option = pytestconfig.getoption("--browser-channel")
if browser_channel_option:
launch_options["channel"] = browser_channel_option
Expand All @@ -120,6 +127,16 @@ def browser_type_launch_args(pytestconfig: Any) -> Dict:
return launch_options


def _is_debugger_attached() -> bool:
pydevd = sys.modules.get("pydevd")
if not pydevd or not hasattr(pydevd, "get_global_debugger"):
return False
debugger = pydevd.get_global_debugger()
if not debugger or not hasattr(debugger, "is_attached"):
return False
return debugger.is_attached()


def _build_artifact_test_folder(
pytestconfig: Any, request: pytest.FixtureRequest, folder_or_file_name: str
) -> str:
Expand Down

0 comments on commit 456f828

Please sign in to comment.