Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion click_repl/globals_.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .core import ReplContext


ISATTY = sys.stdin.isatty()
ISATTY = sys.stdin is not None and sys.stdin.isatty()


@overload
Expand Down
21 changes: 21 additions & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Importing the package must work without an attached standard input."""

import os
import subprocess
import sys


def test_import_without_stdin():
# Closing fd 0 causes Python to expose sys.stdin as None. Test in a
# child so the test runner's own input stream remains untouched.
if os.name == "nt":
code = "import sys; sys.stdin = None; import click_repl"
result = subprocess.run([sys.executable, "-c", code], capture_output=True)
else:
result = subprocess.run(
[sys.executable, "-c", "import sys; assert sys.stdin is None; "
"import click_repl"],
capture_output=True,
preexec_fn=lambda: os.close(0),
)
assert result.returncode == 0, result.stderr.decode(errors="replace")
Loading