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

Classes

class

truncated documentation

TestWrappedException

Raised by @see fn main_wrapper_tests

Functions

function

truncated documentation

main_wrapper_tests

Calls function main and throws an exception if it fails.

Documentation

This extension contains various functionalities to help unittesting.

source on GitHub

exception pyquickhelper.pycode.utils_tests.TestWrappedException[source][source]

Bases: Exception

Raised by @see fn main_wrapper_tests

pyquickhelper.pycode.utils_tests.main_wrapper_tests(logfile, skip_list=None, processes=False, add_coverage=False, report_folder=None, skip_function=<function default_skip_function>, setup_params=None, only_setup_hook=False, coverage_options=None, coverage_exclude_lines=None, additional_ut_path=None, covtoken=None, hook_print=True, stdout=None, stderr=None, filter_warning=None, dump_coverage=None, add_coverage_folder=None, coverage_root='src', fLOG=<function noLOG>)[source][source]

Calls function main and throws an exception if it fails.

Parameters
  • 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

  • setup_params – parameters sent to call_setup_hook

  • only_setup_hook – calls only call_setup_hook, do not run the 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

  • hook_print – enable print display when calling _setup_hook

  • 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
build_setup_help_on_windows.bat

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. Calls function _setup_hook if it is available in the unit tested module. Parameter tested_module was added, the function then checks the presence of function _setup_hook, it is the case, it runs it.

Parameter setup_params: a mechanism was put in place to let the module to test a possibility to run some preprocessing steps in a separate process. They are described in _setup_hook which must be found in the main file __init__.py. Parameter only_setup_hook: saves the report in XML format, binary format, replace full paths by relative path.

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:

coverage_options=dict(omit=["*exclude*.py"])

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

Changed in version 1.8: Parameter coverage_root was added.

source on GitHub