Pytest Quick Start Guide : Write Better Python Code with Simple and Maintainable Tests.
Python's built-in unittest module is showing it's age; hard to extend, debug and track what's going on. The pytest framework overcomes these problems and simplifies testing your Python software. Many users love to use pytest and the improvement in their testing shows! This book is the...
Clasificación: | Libro Electrónico |
---|---|
Autor principal: | |
Formato: | Electrónico eBook |
Idioma: | Inglés |
Publicado: |
Birmingham :
Packt Publishing Ltd,
2018.
|
Temas: | |
Acceso en línea: | Texto completo |
Tabla de Contenidos:
- Cover; Title Page; Copyright and Credits; Packt Upsell; Foreword; Contributors; Table of Contents; Preface; Chapter 1: Writing and Running Tests; Installing pytest; pip and virtualenv; Writing and running tests; Running tests; Powerful asserts; Text differences; Lists; Dictionaries and sets; How does pytest do it?; Checking exceptions: pytest.raises; Checking exception messages; Checking warnings: pytest.warns; Comparing floating point numbers: pytest.approx; Organizing files and packages; Tests that accompany your code; Tests separate from your code; Useful command-line options.
- Keyword expressions: -kStop soon: -x,
- maxfail; Last failed, failed first:
- lf,
- ff; Output capturing: -s and
- capture; Disabling capturing with -s; Capture methods with
- capture; Traceback modes and locals:
- tb,
- showlocals;
- tb=long;
- tb=short;
- tb=native;
- tb=line;
- tb=no;
- showlocals ( -l); Slow tests with
- durations; Extra test summary: -ra; Configuration: pytest.ini; Additional command-line: addopts; Customizing a collection; Cache directory: cache_dir; Avoid recursing into directories: norecursedirs; Pick the right place by default: testpaths.
- Override options with -o/
- overrideSummary; Chapter 2: Markers and Parametrization; Mark basics; Creating marks; Running tests based on marks; Applying marks to classes; Applying marks to modules; Custom marks and pytest.ini; Built-in marks; @pytest.mark.skipif; pytest.skip; pytest.importorskip; @pytest.mark.xfail; pytest.xfail; Parametrization; Enter @pytest.mark.parametrize; Applying marks to value sets; Customizing test IDs; Testing multiple implementations; Summary; Chapter 3: Fixtures; Introducing fixtures; Enter fixtures; Setup/teardown; Composability.
- Sharing fixtures with conftest.py filesScopes; Scopes in action; Autouse; @pytest.mark.usefixtures; Parametrizing fixtures; Using marks from fixtures; An overview of built-in fixtures; tmpdir; tmpdir_factory; monkeypatch; How and where to patch; capsys/capfd; Binary mode; request; Tips/discussion; When to use fixtures, as opposed to simple functions; Renaming fixtures; Prefer local imports in conftest files; Fixtures as test-supporting code; Summary; Chapter 4: Plugins; Finding and installing plugins; Finding plugins; Installing plugins; An overview of assorted plugins; pytest-xdist.
- Pytest-covpytest-faulthandler; pytest-mock; pytest-django; pytest-flakes; pytest-asyncio; pytest-trio; pytest-tornado; pytest-postgresql; docker-services; pytest-selenium; pytest-html; pytest-cpp; pytest-timeout; pytest-annotate; pytest-qt; pytest-randomly; pytest-datadir; pytest-regressions; Honorable mentions; Summary; Chapter 5: Converting unittest suites to pytest; Using pytest as a test runner; Pytest features in unittest subclasses; Converting asserts with unitest2pytest; Handling setup/teardown; Managing test hierarchies; Reusing test code with fixtures; Refactoring test utilities.