module pycode.utils_tests

Inheritance diagram of pyquickhelper.pycode.utils_tests

Short summary

module pyquickhelper.pycode.utils_tests

This extension contains various functionalities to help unittesting.

source on GitHub



truncated documentation


Raised by @see fn main_wrapper_tests



truncated documentation



Calls function main and throws an exception if it fails.


This extension contains various functionalities to help unittesting.

source on GitHub

exception pyquickhelper.pycode.utils_tests.TestWrappedException[source]

Bases: Exception

Raised by @see fn main_wrapper_tests

pyquickhelper.pycode.utils_tests._modifies_coverage_report(name, bsrcp, bproj)[source]
pyquickhelper.pycode.utils_tests.main_wrapper_tests(logfile, skip_list=None, processes=False, add_coverage=False, report_folder=None, skip_function=None, coverage_options=None, coverage_exclude_lines=None, additional_ut_path=None, covtoken=None, stdout=None, stderr=None, filter_warning=None, dump_coverage=None, add_coverage_folder=None, coverage_root='src', fLOG=None)[source]

Calls function main and throws an exception if it fails.

  • logfile – locatio of a logfile

  • skip_list – to skip a list of unit tests (by index, starting by 1)

  • processes – to run the unit test in a separate process (with function run_cmd), however, to make that happen, you need to specify exit=False for each test file, see unittest.main

  • add_coverage – (bool) run the unit tests and measure the coverage at the same time

  • report_folder – (str) folder where the coverage report will be stored

  • skip_functionfunction(filename,content,duration) –> boolean to skip a unit test

  • coverage_options – (dict) options for module coverage as a dictionary, see below, default is None

  • coverage_exclude_lines – (list) options for module coverage, lines to exclude from the coverage report, defaul is None

  • additional_ut_path – (list) additional paths to add when running the unit tests

  • covtoken – (str|tuple(str, str)) token used when publishing coverage report to codecov or None to not publish

  • stdout – if not None, write output on this stream instead of sys.stdout

  • stderr – if not None, write errors on this stream instead of sys.stderr

  • filter_warning – function which removes some warnings in the final output, if None, the function filters out some recurrent warnings in jupyter (signature: def filter_warning(w: warning) -> bool), default_filter_warning

  • dump_coverage – dump or copy the coverage at this location

  • add_coverage_folder – additional coverage folder reports

  • coverage_root – subfolder for the coverage

  • fLOGfunction(*l, **p), logging function

covtoken can be a string <token> or a tuple (<token>, <condition>). The condition is evaluated by the python interpreter and determines whether or not the coverage needs to be published.

How to build pyquickhelper with Jenkins?

Jenkins is a task scheduler for continuous integration. You can easily schedule batch command to build and run unit tests for a specific project. To build pyquickhelper, you need to install python, pymyinstall, miktex, pandoc, sphinx.

Once Jenkins is installed, the command to schedule is:

set PATH=%PATH%;%USERPOFILE%\AppData\Local\Pandoc

This works if you installed Jenkins with your credentials. Otherwise, the path to pandoc.exe needs to be changed. And you can also read Schedule builds with Jenkins. node.js might be required if a notebooks contain javascript.

Parameters add_coverage and report_folder are used to compute the coverage using the module coverage. The function does something about the following error:

_tkinter.TclError: no display name and no $DISPLAY environment variable

It is due to matplotlib. See Generating matplotlib graphs without a running X server. If the skip function is None, it will replace it by the function default_skip_function.

Parameters coverage_options, coverage_exclude_lines, additional_ut_path: see class Coverage and Configuration files to specify those options. If both values are left to None, this function will compute the code coverage for all files in this module. The function now exports the coverage options which were used. For example, to exclude files from the coverage report:


Parameter covtoken: used to post the coverage report to codecov.

source on GitHub