Repository: mpl-extensions/mpl-interactions (language: python)

Issue:
Detect and run doctests with pytest
When running `pytest --collect-only` (which happens for instance when you want to explore the tests in VSCode), some matplotlib plots are created. This means there is some code that is not within a (test) function, which slows down test discovery.


Discussion / hints:
Does this happen when you run in the terminal? Looking through the tests I don't see anywhere this would happen. When I run `pytest --collect-only` from the terminal no figures are created and it claims to have collected all in `.41` seconds. 
Ohh hang on, sorry :expressionless: It's after I added the doctest-modules flag that some scripts were run...
So was a bit too fast posting this. Still, it would be nice to let pytest detect any potential doctests without error.

Fix patch:
diff --git a/.gitignore b/.gitignore
index 2582d65a..42e41e50 100644
--- a/.gitignore
+++ b/.gitignore
@@ -130,5 +130,16 @@ dmypy.json
 
 *.swp
 
-# Test output
-animation-*.gif
+_build
+
+# autoapi stuff - may be bad to ignore this idk
+autoapi
+
+# notebooks in the docs folder
+# this is to enable the madness with adding gifs
+docs/examples/tidbits/*.ipynb
+docs/examples/*.ipynb
+docs/examples/*.gif
+docs/*.ipynb
+docs/gallery
+
diff --git a/.vscode/settings.json b/.vscode/settings.json
index d367c961..dffaa5d0 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -20,5 +20,5 @@
   "python.formatting.provider": "black",
   "python.languageServer": "Pylance",
   "python.linting.enabled": false,
-  "python.analysis.completeFunctionParens": true
+  "python.testing.pytestEnabled": true
 }
diff --git a/docs/examples/scatter-selector.ipynb b/docs/examples/scatter-selector.ipynb
index 975f1fb3..18cdc6e8 100644
--- a/docs/examples/scatter-selector.ipynb
+++ b/docs/examples/scatter-selector.ipynb
@@ -49,7 +49,7 @@
     "\n",
     "For this example we have pre-cleaned data that we will just load. If you are curious on how the data was originally processed you see the full code at the bottom of this notebook.\n",
     "\n",
-    "The datafiles that we load for this example are available for download at <https://github.com/ianhi/mpl-interactions/tree/master/examples/data>"
+    "The datafiles that we load for this example are available for download at <https://github.com/ianhi/mpl-interactions/tree/master/docs/examples/data>"
    ]
   },
   {
diff --git a/pyproject.toml b/pyproject.toml
index 11b87ab5..5de89fb6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,3 +4,20 @@ line-length = 100
 [tool.isort]
 profile = "black"
 line_length = 100
+
+[tool.pytest.ini_options]
+testpaths = ["docs/examples", "tests"]
+norecursedirs = [
+    ".ipynb_checkpoints",
+    "devlop",
+    "docs/examples/gallery",
+    "node_modules",
+]
+addopts = [
+    "--current-env",
+    "--doctest-continue-on-failure",
+    "--doctest-modules",
+    "--ignore-glob=docs/examples/*.py",
+    "--mpl",
+    "--nbval",
+]


Test patch:
diff --git a/pytest.ini b/pytest.ini
deleted file mode 100644
index 31d1b926..00000000
--- a/pytest.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[pytest]
-testpaths =
-    docs/examples
-    mpl_interactions/tests
-norecursedirs = node_modules .ipynb_checkpoints devlop
-addopts = --nbval --current-env --mpl
diff --git a/mpl_interactions/tests/__init__.py b/tests/__init__.py
similarity index 100%
rename from mpl_interactions/tests/__init__.py
rename to tests/__init__.py
diff --git a/mpl_interactions/tests/baseline/test_heatmap_slicer.png b/tests/baseline/test_heatmap_slicer.png
similarity index 100%
rename from mpl_interactions/tests/baseline/test_heatmap_slicer.png
rename to tests/baseline/test_heatmap_slicer.png
diff --git a/mpl_interactions/tests/baseline/test_heatmap_slicer32.png b/tests/baseline/test_heatmap_slicer32.png
similarity index 100%
rename from mpl_interactions/tests/baseline/test_heatmap_slicer32.png
rename to tests/baseline/test_heatmap_slicer32.png
diff --git a/mpl_interactions/tests/baseline/test_hist_controls.png b/tests/baseline/test_hist_controls.png
similarity index 100%
rename from mpl_interactions/tests/baseline/test_hist_controls.png
rename to tests/baseline/test_hist_controls.png
diff --git a/mpl_interactions/tests/baseline/test_hist_plot.png b/tests/baseline/test_hist_plot.png
similarity index 100%
rename from mpl_interactions/tests/baseline/test_hist_plot.png
rename to tests/baseline/test_hist_plot.png
diff --git a/mpl_interactions/tests/baseline/test_image_segmentation.png b/tests/baseline/test_image_segmentation.png
similarity index 100%
rename from mpl_interactions/tests/baseline/test_image_segmentation.png
rename to tests/baseline/test_image_segmentation.png
diff --git a/mpl_interactions/tests/baseline/test_mixed_types.png b/tests/baseline/test_mixed_types.png
similarity index 100%
rename from mpl_interactions/tests/baseline/test_mixed_types.png
rename to tests/baseline/test_mixed_types.png
diff --git a/mpl_interactions/tests/baseline/test_multiple_functions.png b/tests/baseline/test_multiple_functions.png
similarity index 100%
rename from mpl_interactions/tests/baseline/test_multiple_functions.png
rename to tests/baseline/test_multiple_functions.png
diff --git a/mpl_interactions/tests/baseline/test_styling.png b/tests/baseline/test_styling.png
similarity index 100%
rename from mpl_interactions/tests/baseline/test_styling.png
rename to tests/baseline/test_styling.png
diff --git a/mpl_interactions/tests/test_controls.py b/tests/test_controls.py
similarity index 82%
rename from mpl_interactions/tests/test_controls.py
rename to tests/test_controls.py
index adaa11b1..cf07d4a4 100644
--- a/mpl_interactions/tests/test_controls.py
+++ b/tests/test_controls.py
@@ -1,3 +1,5 @@
+from pathlib import Path
+
 import ipywidgets as widgets
 import matplotlib.pyplot as plt
 import numpy as np
@@ -28,7 +30,7 @@ def cb(**kwargs):
     assert len(zoop) == 2
 
 
-def test_save_animation():
+def test_save_animation(tmp_path: Path):
     # just test that no errors are thrown, don't actually check
     # that the saved animation makes any sense. Doing that seems hard :(
     x = np.linspace(0, np.pi, 100)
@@ -50,6 +52,6 @@ def f2(x, amp, tau, beta):
     iplt.plot(x, f1, ax=ax, controls=ctrls)
     iplt.plot(x, f2, ax=ax, controls=ctrls)
 
-    ctrls.save_animation("animation-amp.gif", fig, "amp", N_frames=10)
-    ctrls.save_animation("animation-beta.gif", fig, "beta")
-    ctrls.save_animation("animation-tau.gif", fig, "tau")
+    ctrls.save_animation(str(tmp_path / "animation-amp.gif"), fig, "amp", N_frames=10)
+    ctrls.save_animation(str(tmp_path / "animation-beta.gif"), fig, "beta")
+    ctrls.save_animation(str(tmp_path / "animation-tau.gif"), fig, "tau")
diff --git a/mpl_interactions/tests/test_generic.py b/tests/test_generic.py
similarity index 92%
rename from mpl_interactions/tests/test_generic.py
rename to tests/test_generic.py
index 92904142..d734ab5b 100644
--- a/mpl_interactions/tests/test_generic.py
+++ b/tests/test_generic.py
@@ -41,8 +41,7 @@ def test_image_segmentation():
         "https://github.com/matplotlib/matplotlib/raw/v3.3.0/lib/matplotlib/mpl-data/sample_data/ada.png"
     )
     script_dir = realpath(dirname(__file__))
-    mask_file = "examples/ada-mask.npy"
-    mask = np.load(f"{script_dir}/../../docs/{mask_file}")
+    mask = np.load(f"{script_dir}/../docs/examples/ada-mask.npy")
     preloaded = image_segmenter(image, nclasses=3, mask=mask)
 
     return preloaded.fig
diff --git a/mpl_interactions/tests/test_helpers.py b/tests/test_helpers.py
similarity index 100%
rename from mpl_interactions/tests/test_helpers.py
rename to tests/test_helpers.py
diff --git a/mpl_interactions/tests/test_pyplot.py b/tests/test_pyplot.py
similarity index 100%
rename from mpl_interactions/tests/test_pyplot.py
rename to tests/test_pyplot.py