A handy Python test framework (pytest) and its CI settings __python

Source: Internet
Author: User
background

Some of our formal code is written in Python, and this part of the code needs TDD, so we need to find a useful test framework. Framework Selection

Python's Test Tools encyclopedia:
Https://wiki.python.org/moin/PythonTestingToolsTaxonomy

Python Mainstream testing tools for horizontal comparisons
http://docs.python-guide.org/en/latest/writing/tests/
http://pythontesting.net/test-podcast/

According to the following article, we decided to use the Pytest
Http://mathieu.agopian.info/presentations/2015_06_djangocon_europe/?full#cover

Official information of Pytest
integration of http://wiki.zte.com.cn/pages/viewpage.action?pageId=38150854 CI

Normal pytest installation is not covered by coverage

Pip Install Pytest

Pytest coverage requires additional installation

Pip Install Pytest-cov

At this time, the new Py.test command, which is the original Pytest command on the basis of encapsulation, new coverage features.

Example Demonstration:

Py.test test_conf2bin.py--junit-xml=test_conf2bin_report.xml--cov-report=html--cov-config=.coveragerc--cov=./
Test_conf2bin.py is the target test file –junit-xml=test_conf2bin_report.xml is the test_conf2bin_report.xml–cov-report=html that generates the JUnit format The report –COV-CONFIG=.COVERAGERC the output HTML uses the. COVERAGERC configuration file (Py.test is based on coverage.py and therefore supports coverage.py configuration files)

–cov=./this is necessary, without this, will be unable to output HTML report

. Coveragerc This file allows Py.test to implement more advanced features, as follows:

[Run]
Branch = True

[the]
include = conf2bin.py

[HTML]
directory = Python_coverage_report

[The]
Include = conf2bin.py
Because Py.test accounting for all the files in a folder, if you only need statistics conf2bin.py the coverage of this file, you can write
[HTML]
Directory = Python_coverage_report
Refers to the HTML output folder last

Pytest personal trial, indeed very good, more than the test frame with a strong

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.