Skip to content
This repository has been archived by the owner on Feb 18, 2020. It is now read-only.

lancelote/pluralsight-unit-testing-python

Repository files navigation

Requirements Status Build Status Coverage Status

pluralsight-unit-testing-python

Code for pluralsight course Unit Testing with Python by Emily Bache

Notes

  • Stub - returns a hard coded answer to any query (no logic)
  • Fake - is a real implementation, yet unsuitable for production
  • Mock - is as a Stub, but additionally verifies interactions
  • Test Spy - lets you query afterwards to find out what happened
  • Dummy - is for when the interface requires an argument
  • Monkeypatching - changing code at runtime

Progress

  • Unit Testing with Python - Basic Example Using unittest
  • Why and When Should You Write Unit Tests
  • Using Pytest for Unit Testing in Python
  • Testable Documentation with Doctest
  • Test Doubles: Mocks, Fakes and Stubs
  • Test Coverage and Parameterized Tests

Unittest

python -m unittest -v

Pytest

python -m pytest --doctest-modules -v

Doctest

Should be in proper folder:

python -m doctest test_* -v

Test Coverage

  • coverage and pytest-cov packages are required
  • Add pragma: no cover to exclude code from coverage report

With pytest

Terminal report:

python -m pytest --cov-report term-missing --cov <target>

HTML report:

python -m pytest --cov-report html --cov <target>

With unittest

To generate report:

python -m coverage run -m unittest

To view report in terminal:

python -m coverage report

To view report in HTML:

python -m coverage html

Coverage Branch feature

  • Create .coveragerc
  • Add - Add following code to it
[run]
branch=True

About

Code for Unit Testing with Python pluralsight course

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages