pytest Quick Start Guide
Bruno Oliveira更新时间:2021-07-16 17:51:50
最新章节:Leave a review - let other readers know what you think封面
Title Page
Copyright and Credits
pytest Quick Start Guide
Packt Upsell
Why subscribe?
PacktPub.com
Foreword
Contributors
About the author
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Introducing pytest
Why spend time writing tests?
A quick look at the unittest module
Why pytest?
Summary
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: -k
Stop 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/--override
Summary
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
Fixtures
Introducing fixtures
Enter fixtures
Setup/teardown
Composability
Sharing fixtures with conftest.py files
Scopes
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
Plugins
Finding and installing plugins
Finding plugins
Installing plugins
An overview of assorted plugins
pytest-xdist
pytest-cov
pytest-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
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
Migration strategy
Summary
Wrapping Up
Overview of what we have learned
Introduction
Writing and running tests
Marks and parametrization
Fixtures
Plugins
Converting unittest suites to pytest
The pytest community
Getting involved
2016 Sprint
Next steps
Final summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
更新时间:2021-07-16 17:51:50