File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ import nbformat
4
+
5
+ import pytest
6
+
7
+ from utils import build_nb
8
+
9
+
10
+ pytest_plugins = "pytester"
11
+
12
+ @pytest .mark .parametrize ("magic, expected_passes" , [
13
+ (r"%dirs" , [True ]),
14
+ (r"%this_magic_does_not_exist" , [False ])
15
+ ])
16
+ def test_magics (testdir , magic , expected_passes ):
17
+ # Setup notebook to test:
18
+ sources = [
19
+ # In [1]:
20
+ magic ,
21
+ ]
22
+ nb = build_nb (sources )
23
+
24
+ # Write notebook to test dir
25
+ nbformat .write (nb , os .path .join (
26
+ str (testdir .tmpdir ), 'test_magics.ipynb' ))
27
+
28
+ # Run tests
29
+ result = testdir .inline_run ('--nbval-lax' , '--current-env' , '-s' )
30
+ reports = result .getreports ('pytest_runtest_logreport' )
31
+
32
+ # Setup and teardown of cells should have no issues:
33
+ setup_teardown = [r for r in reports if r .when != 'call' ]
34
+ for r in setup_teardown :
35
+ assert r .passed
36
+
37
+ reports = [r for r in reports if r .when == 'call' ]
38
+
39
+ assert len (reports ) == len (expected_passes )
40
+
41
+ for actual_report , expected_pass in zip (reports , expected_passes ):
42
+ assert actual_report .passed is expected_pass
You can’t perform that action at this time.
0 commit comments