Skip to content

Commit

Permalink
CI: change working directory and close figures during tutorial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Sep 6, 2024
1 parent d5a5343 commit 5a4833e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/test_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
A couple notes:
- the tutorials require a number of extra dependencies and data files to be present
check out the test-tutorials.yml workflow to see how this is set up.
- it's possible that any notebook that spawns another child process (e.g. the SWC I/O tutorial)
will hang indefinitely. This is because of the ominous "An attempt has been made to start a new
process before the current process has finished its bootstrapping phase." error which typically
means that the script has to be run in a `if __name__ == "__main__":` block.
Set `capture_output=True` to see the error message.
- the MICrONS tutorial occasionally fails because the CAVE backend throws an error
(e.g. during the materialization)
- Github runners appear to have 4 CPUs - so should be good to go
Expand All @@ -19,6 +14,9 @@
import os
import sys
import navis
import warnings

import matplotlib.pyplot as plt

from pathlib import Path
from contextlib import contextmanager
Expand All @@ -38,8 +36,13 @@ def suppress_stdout():

# Silence logging
navis.config.logger.setLevel("ERROR")

# Hide pbars
navis.set_pbars(hide=True)

# Silence warnings
warnings.filterwarnings("ignore")


if __name__ == "__main__":
# Recursively search for notebooks
Expand All @@ -52,9 +55,17 @@ def suppress_stdout():
if file.name in SKIP:
continue

# Note: we're using `exec` here instead of e.g. `subprcoess.run` because we need to avoid
# the "An attempt has been made to start a new process before the current process has
# finished its bootstrapping phase" error that occurs when using multiprocessing with "spawn"
# from a process where it's not wrapped in an `if __name__ == "__main__":` block.
print(f"Executing {file.name} [{i+1}/{len(files)}]... ", end="", flush=True)
with suppress_stdout():
exec(open(file).read())
os.chdir(file.parent)
exec(open(file.name).read())
print("Done.", flush=True)

# Make sure to close any open figures
plt.close()

print("All done.")

0 comments on commit 5a4833e

Please sign in to comment.