|
9 | 9 |
|
10 | 10 | pytest_plugins = "pytester" |
11 | 11 |
|
12 | | -@pytest.mark.parametrize("magic, expected_passes", [ |
13 | | - (r"%dirs", [True]), |
14 | | - (r"%precision bad", [False]), |
15 | | - (r"%this_magic_does_not_exist", [False]) |
| 12 | +@pytest.mark.parametrize("magic, expected_pass", [ |
| 13 | + (r"%dirs", True), |
| 14 | + (r"%precision bad", False), |
| 15 | + (r"%this_magic_does_not_exist", False) |
16 | 16 | ]) |
17 | | -def test_magics(testdir, magic, expected_passes): |
18 | | - # Setup notebook to test: |
19 | | - sources = [ |
| 17 | +def test_magics(testdir, magic, expected_pass): |
| 18 | + nb = build_nb([ |
20 | 19 | # In [1]: |
21 | 20 | magic, |
22 | | - ] |
23 | | - nb = build_nb(sources) |
24 | | - |
25 | | - # Write notebook to test dir |
| 21 | + ]) |
| 22 | + nb_name = 'test_magics' |
26 | 23 | nbformat.write(nb, os.path.join( |
27 | | - str(testdir.tmpdir), 'test_magics.ipynb')) |
28 | | - |
29 | | - # Run tests |
30 | | - result = testdir.inline_run('--nbval-lax', '--current-env', '-s') |
31 | | - reports = result.getreports('pytest_runtest_logreport') |
32 | | - |
33 | | - # Setup and teardown of cells should have no issues: |
34 | | - setup_teardown = [r for r in reports if r.when != 'call'] |
35 | | - for r in setup_teardown: |
36 | | - assert r.passed |
| 24 | + str(testdir.tmpdir), nb_name+".ipynb")) |
37 | 25 |
|
38 | | - reports = [r for r in reports if r.when == 'call'] |
| 26 | + # using subprocess because otherwise second and subsequent tests always fail (some state left over somewhere in the jupyter stack) |
| 27 | + result = testdir.runpytest_subprocess('--nbval-lax', '--current-env', '-s', '-v') |
39 | 28 |
|
40 | | - assert len(reports) == len(expected_passes) |
| 29 | + assert result.ret == (not expected_pass) |
41 | 30 |
|
42 | | - for actual_report, expected_pass in zip(reports, expected_passes): |
43 | | - assert actual_report.passed is expected_pass |
| 31 | + result.stdout.fnmatch_lines_random( |
| 32 | + ["*collected 1 item*", |
| 33 | + "{nb_name}::ipynb::Cell 0 {result}".format(nb_name=nb_name, result="PASSED" if expected_pass else "FAILED")]) |
0 commit comments