Skip to content

Commit

Permalink
Capturing sys.stdout too early breaks pytest capfd
Browse files Browse the repository at this point in the history
Since at least testing and possibly users may update
sys.stdout after importing the module, we defer the
evaluation of `sys.stdout` until the last possible
opportunity.
  • Loading branch information
joshmoore committed Dec 11, 2024
1 parent d234329 commit bb5e4de
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/omero_rdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@


@contextlib.contextmanager
def open_with_default(filename=None, filehandle=sys.stdout):
def open_with_default(filename=None, filehandle=None):
"""
Open a file for writing if given and close on completion.
Expand All @@ -88,6 +88,8 @@ def open_with_default(filename=None, filehandle=sys.stdout):
fh = open(filename, "w")
close = True
else:
if filehandle is None:
filehandle = sys.stdout
fh = filehandle

try:
Expand Down

0 comments on commit bb5e4de

Please sign in to comment.