Skip to content

Commit

Permalink
fix: stderr redirect with monkeypatched stderr (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Aug 7, 2020
1 parent 5580420 commit 05e48f6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion playwright/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import asyncio
import io
import subprocess
import sys
from typing import Any
Expand Down Expand Up @@ -45,11 +46,21 @@ async def run_driver_async() -> Connection:
driver_name = compute_driver_name()
driver_executable = package_path / "drivers" / driver_name

# Sourced from: https://github.com/pytest-dev/pytest/blob/49827adcb9256c9c9c06a25729421dcc3c385edc/src/_pytest/faulthandler.py#L73-L80
def _get_stderr_fileno() -> int:
try:
return sys.stderr.fileno()
except io.UnsupportedOperation:
# pytest-xdist monkeypatches sys.stderr with an object that is not an actual file.
# https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors
# This is potentially dangerous, but the best we can do.
return sys.__stderr__.fileno()

proc = await asyncio.create_subprocess_exec(
str(driver_executable),
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=sys.stderr,
stderr=_get_stderr_fileno(),
limit=32768,
)
assert proc.stdout
Expand Down

0 comments on commit 05e48f6

Please sign in to comment.