Skip to content

Commit 05e48f6

Browse files
authored
fix: stderr redirect with monkeypatched stderr (microsoft#159)
1 parent 5580420 commit 05e48f6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

playwright/main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
import io
1617
import subprocess
1718
import sys
1819
from typing import Any
@@ -45,11 +46,21 @@ async def run_driver_async() -> Connection:
4546
driver_name = compute_driver_name()
4647
driver_executable = package_path / "drivers" / driver_name
4748

49+
# Sourced from: https://github.com/pytest-dev/pytest/blob/49827adcb9256c9c9c06a25729421dcc3c385edc/src/_pytest/faulthandler.py#L73-L80
50+
def _get_stderr_fileno() -> int:
51+
try:
52+
return sys.stderr.fileno()
53+
except io.UnsupportedOperation:
54+
# pytest-xdist monkeypatches sys.stderr with an object that is not an actual file.
55+
# https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors
56+
# This is potentially dangerous, but the best we can do.
57+
return sys.__stderr__.fileno()
58+
4859
proc = await asyncio.create_subprocess_exec(
4960
str(driver_executable),
5061
stdin=asyncio.subprocess.PIPE,
5162
stdout=asyncio.subprocess.PIPE,
52-
stderr=sys.stderr,
63+
stderr=_get_stderr_fileno(),
5364
limit=32768,
5465
)
5566
assert proc.stdout

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy