Skip to content

Commit

Permalink
stdout needs to be an open file
Browse files Browse the repository at this point in the history
  • Loading branch information
sroet authored Aug 16, 2024
1 parent 707c347 commit add2372
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/tutorials/tests/test_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ def sanitize_block(block):
print(f"{block.split()=}")
if block.split()[0].endswith(".py"):
print(f"Running: {block}")
# Check=True makes sure this code returns early

block = sanitize_block(block)
outfile = None
# Deal with stdout redirect
if block[-2] == ">":
outfile = block[-1]
outfile = open(block[-1])
block = block[:-2]
# Check=True makes sure this code returns early
subprocess.run(block, check=True, stdout=outfile)
if outfile is not None:
outfile.close()

0 comments on commit add2372

Please sign in to comment.