Skip to content

Latest commit

 

History

History
96 lines (68 loc) · 2.1 KB

python_testing_slides.md

File metadata and controls

96 lines (68 loc) · 2.1 KB
type slide
slideOptions
transition width height margin
slide
1400
900
0.1
<style> .reveal strong { font-weight: bold; color: orange; } .reveal p { text-align: left; } .reveal section h1 { color: orange; } .reveal section h2 { color: orange; } </style>

Testing a Python Code


pytest

  • Package to write and manage tests.
  • Includes command-line interface called pytest.
  • All tests need to be in files named test_*.py.
  • Each test function needs to be named as test_*.
  • pytest gives a detailed description for failing tests.

pytest Demo


unittest

  • Python framework specifically designed to run, monitor and automate unit tests.
  • Many features like test automation, sharing of setup and shutdown of tests, etc.
  • Use the base class unittest.TestCase to create a test suite.
  • MagicMock from unittest.mock used for mock testing.
  • Command-line interface: python -m unittest.
  • Part of the Python standard library.

unittest Demo


coverage

  • Python library to check code coverage
  • Testing frameworks can be run via coverage to generate code coverage data while tests run.
  • Code coverage information can be viewed on the terminal using: coverage report -m.

coverage Demo


tox

  • Environment orchestrator to setup and execute various tools for a project.
  • Creates virtual environments for each process.
  • Processes include testing, linting, building, documentation generation, and more.
  • Configuration via tox.toml or tox.ini file.

tox Demo


Other Testing Frameworks

  • nose is an extension to unittest with added plugins.
  • testify based on unittest and nose with additional features.
  • robotframework is a generic automation framework.

Further Reading