Some tests with custom flags.

Note: no need to default_exp if you want to have only tests in a notebook

To run all non-flagged tests

  • nbdev_test_nbs

To run all tests and tests flagged with failing_test

  • nbdev_test_nbs --flags failing_test
import os
# run with: `nbdev_test_nbs --flags failing_test --fname 30_test_flag.ipynb`
if os.environ.get('IN_TEST', 0): 1/0

The next section checks that flagged tests are run correctly. Any of the following should pass;

export EXEPECTED_TST_FLAGS="cython slow"
nbdev_test_nbs --flags "cython slow" --fname 30_test_flag.ipynb

export EXEPECTED_TST_FLAGS="slow"
nbdev_test_nbs --flags "slow" --fname 30_test_flag.ipynb

export EXEPECTED_TST_FLAGS=
nbdev_test_nbs --fname 30_test_flag.ipynb

but these should fail;

export EXEPECTED_TST_FLAGS="slow"
nbdev_test_nbs --flags "cython slow" --fname 30_test_flag.ipynb

export EXEPECTED_TST_FLAGS="cython slow"
nbdev_test_nbs --flags "slow" --fname 30_test_flag.ipynb

export EXEPECTED_TST_FLAGS="cython slow"
nbdev_test_nbs --fname 30_test_flag.ipynb
test_log=[]
test_log.append('cython')
# TODO: add some cython code
if os.environ.get('IN_TEST', 0):
    def sort_unique(l):
        l.sort()
        return set(l)
    expected = sort_unique(os.environ.get('EXEPECTED_TST_FLAGS', '').split())
    actual = sort_unique(test_log)
    print(expected, actual)
    if expected != actual:
        raise Exception(f'Expected {expected} test flags to be run but found {actual}')