Python Testing with Pytest: Simple, Rapid, Effective, and Scalable

Brian Okken

買這商品的人也買了...

商品描述

Do less work when testing your Python code, but be just as expressive, just as elegant, and just as readable. The pytest testing framework helps you write tests quickly and keep them readable and maintainable - with no boilerplate code. Using a robust yet simple fixture model, it's just as easy to write small tests with pytest as it is to scale up to complex functional testing for applications, packages, and libraries. This book shows you how.

For Python-based projects, pytest is the undeniable choice to test your code if you're looking for a full-featured, API-independent, flexible, and extensible testing framework. With a full-bodied fixture model that is unmatched in any other tool, the pytest framework gives you powerful features such as assert rewriting and plug-in capability - with no boilerplate code.

With simple step-by-step instructions and sample code, this book gets you up to speed quickly on this easy-to-learn and robust tool. Write short, maintainable tests that elegantly express what you're testing. Add powerful testing features and still speed up test times by distributing tests across multiple processors and running tests in parallel. Use the built-in assert statements to reduce false test failures by separating setup and test failures. Test error conditions and corner cases with expected exception testing, and use one test to run many test cases with parameterized testing. Extend pytest with plugins, connect it to continuous integration systems, and use it in tandem with tox, mock, coverage, unittest, and doctest.

Write simple, maintainable tests that elegantly express what you're testing and why.

What You Need:

The examples in this book are written using Python 3.6 and pytest 3.0. However, pytest 3.0 supports Python 2.6, 2.7, and Python 3.3-3.6.

商品描述(中文翻譯)

測試你的Python程式碼時,可以做更少的工作,但表達力、優雅度和可讀性都不會減少。pytest測試框架可以幫助你快速撰寫測試並保持其可讀性和可維護性,而且不需要冗長的程式碼。使用堅固而簡單的fixture模型,使用pytest撰寫小型測試和複雜功能測試(應用程式、套件和函式庫)同樣容易。本書將向你展示如何使用pytest。

對於基於Python的專案,如果你正在尋找一個功能完整、獨立於API、靈活且可擴展的測試框架,那麼pytest是無可爭議的選擇。pytest擁有無與倫比的fixture模型,提供強大的功能,如斷言重寫和插件能力,而且不需要冗長的程式碼。

本書通過簡單的逐步指示和示例代碼,快速讓你掌握這個易於學習且強大的工具。撰寫簡潔、可維護的測試,優雅地表達你要測試的內容。通過將測試分佈到多個處理器並且並行運行測試,添加強大的測試功能,同時加快測試時間。使用內建的斷言語句,通過分離設置和測試失敗來減少虛假的測試失敗。使用預期的異常測試來測試錯誤條件和邊界情況,並使用一個測試運行多個測試案例。通過插件擴展pytest,將其連接到持續集成系統,並與tox、mock、coverage、unittest和doctest一起使用。

撰寫簡單、可維護的測試,優雅地表達你要測試的內容和原因。

所需工具:
本書中的示例使用Python 3.6和pytest 3.0編寫。然而,pytest 3.0支援Python 2.6、2.7和Python 3.3-3.6。