Skip to main content

Python

The following sections provide information on using Testspace with popular Python test frameworks and tools.

To push collected files simply use the Testspace client:

$ testspace static-analysis-results test-results code-coverage-results

Test Frameworks

pytest

pytest is a mature full-featured Python testing tool.

Testspace accepts JUnit XML formatted Test results. Here is an example of how to produce such:

pytest --junit-xml=results.xml

In the Testspace client command-line reference results.xml as "test-results" file.

Unittest

The Python unit testing framework, sometimes referred to as "PyUnit", is a Python language version of JUnit, by Kent Beck and Erich Gamma.

Python Unittest sample: https://github.com/testspace-samples/python.unittest

Testspace accepts JUnit XML formatted Test results. Assuming you are using nose2 to run your tests, here is an example of how to produce such:

nose2 --plugin nose2.plugins.junitxml --junit-xml

In the Testspace client command-line reference nose2-junit.xml as "test-results" file.

Code Coverage

Coverage.py

Coverage.py is a tool for measuring code coverage of Python programs.

Testspace accepts Cobertura XML formatted results. Here is an example of how to produce such:

coverage xml -o coverage.xml

Alternatively, you could direct your test runner to produce the desired coverage results:

  • pytest

    Assumes pytest-cov package has been installed and configured.

    $ pytest --cov-report=xml --cov=./
  • nose2

    $ nose2 --with-coverage --coverage-report=xml

In the Testspace client command-line reference coverage.xml as "code-coverage-results" file.

Static Analysis

Flake8

Flake8 is a tool for style guide enforcement for Python.

Testspace accepts GCC/Emacs style formatted output logs. Simply write your analysis output to a file:

flake8 --output-file=analysis.log /path/to/source

In the Testspace client command-line reference analysis.log{lint} as "static-analysis-results" file.

pycodestyle

pycodestyle (formerly called pep8) is a tool to check Python code against some of the style conventions in PEP 8.

Testspace accepts GCC/Emacs style formatted output logs. Simply write your analysis output to a file:

pycodestyle /path/to/source > analysis.log

In the Testspace client command-line reference analysis.log{lint} as "static-analysis-results" file.

Pylint

Pylint is a tool that checks for errors in Python code, tries to enforce a coding standard and looks for code smells.

Testspace accepts GCC/Emacs style formatted output logs. Simply write your analysis output to a file:

pylint --output-format=parseable /path/to/source > analysis.log

In the Testspace client command-line reference analysis.log{lint} as "static-analysis-results" file.