Skip to content

Designing tests

QLutz edited this page Oct 16, 2020 · 6 revisions

Setting up doctest with PyCharm

To get doctest to work smoothly with PyCharm, have a look at François Durand's toy package.

Where to test

Tests serve two distinct purposes in Scikit-network, there are:

  • functional tests which aim at ensuring that the code is running as intended. This makes it possible to develop new features while making sure all previous features still yield correct results.

  • examples which aim at providing the user with the intended use of a function.

Functional tests

Functional tests should be located in a folder named test at the same level as their related module.

Such tests are defined using the unittest.TestCase object.

Examples

Examples should be located in the doc next to the function at stake, using the doctest package.

Examples mainly consist of a copy of a console output:

    >>> a = 1              # defining variables
    >>> print(a)           # test input
    1                      # expected output

Doctest then handles the tests on its own.

Tips & Tricks

  • Make sure that the outputs of your tests do not vary from one machine to another when using doctest (especially if the output of your function is a NumPy array). For instance when running some command f(x), you might expect array([0,1,2]) as a result with a Linux machine as opposed to array([0,1,2], dtype=int64) on a Windows machine. This makes it difficult to define such a test with doctest. To circumvent this issue, consider using the following structure: (f(x) == np.array([0,1,2])).all() and expect True to be returned.