Helper functions to search for api tests

Functional Test Documentation

Generates documentation for fastai's functional tests

Find tests for any function/class

show_test and doctest searches for any implemented tests for a given fastai class or function

For test writers:

  • Use this module to search for tests and get a better idea on which parts of the fastai api need more functional tests

For fastai users:

  • Usage is similar to nbdoc.show_doc and nbdoc.doc.
  • It's here to help you find associated tests for a given function can help understand usage.

Usage:

show_test[source][test]

show_test(elt) → str

No tests found for show_test. To contribute a test please refer to this guide and this discussion.

Show associated tests for a fastai function/class

Show tests from function

from fastai.basic_train import Learner
show_test(Learner.fit)

Tests found for fit:

  • pytest -sv tests/test_train.py::test_fit [source]

Some other tests where fit is used:

  • pytest -sv tests/test_basic_train.py::test_destroy [source]

To run tests please refer to this guide.

Show tests from a Class

from fastai.basic_data import DataBunch
show_test(DataBunch)

Tests found for DataBunch:

  • pytest -sv tests/test_data_block.py::test_custom_dataset [source]

Some other tests where DataBunch is used:

  • pytest -sv tests/test_basic_data.py::test_DataBunch_Create [source]
  • pytest -sv tests/test_basic_data.py::test_DataBunch_no_valid_dl [source]

To run tests please refer to this guide.

from fastai.text.data import TextList
show_test(TextList)

Tests found for TextList:

Some other tests where TextList is used:

  • pytest -sv tests/test_text_data.py::test_filter_classes [source]
  • pytest -sv tests/test_text_data.py::test_from_folder [source]
  • pytest -sv tests/test_text_data.py::test_regression [source]

To run tests please refer to this guide.

Different test types

Above, you will see 2 different test types: Tests found for... and Some other tests...

  • Tests found for... - Searches for function matches in test_registry.json. This json file is populated from doctest.this_tests calls.
  • Some other tests... - Returns any test function where the fastai function in called inside the body

Show in notebook inline:

doctest[source][test]

doctest(elt)

Tests found for doctest:

Some other tests where doctest is used:

  • pytest -sv tests/test_gen_doc_nbtest.py::test_this_tests [source]

To run tests please refer to this guide.

Inline notebook popup for show_test

Internal search methods

lookup_db[source][test]

lookup_db(elt) → List[Dict[KT, VT]]

No tests found for lookup_db. To contribute a test please refer to this guide and this discussion.

Finds this_test entries from test_registry.json

find_related_tests(elt) → Tuple[List[Dict[KT, VT]], List[Dict[KT, VT]]]

Searches fastai/tests folder for any test functions related to elt

find_test_matches[source][test]

find_test_matches(elt, test_file:Path) → Tuple[List[Dict[KT, VT]], List[Dict[KT, VT]]]

No tests found for find_test_matches. To contribute a test please refer to this guide and this discussion.

Find all functions in test_file related to elt

find_test_files[source][test]

find_test_files(elt, exact_match:bool=False) → List[Path]

No tests found for find_test_files. To contribute a test please refer to this guide and this discussion.

Searches in fastai/tests directory for module tests

fuzzy_test_match[source][test]

fuzzy_test_match(fn_name:str, lines:List[Dict[KT, VT]], rel_path:str) → List[TestFunctionMatch]

Tests found for fuzzy_test_match:

  • pytest -sv tests/test_gen_doc_nbtest.py::test_fuzzy_test_match [source]

To run tests please refer to this guide.

Find any lines where fn_name is invoked and return the parent test function