Python Testing with Pytest: Simple, Rapid, Effective, and Scalable
暫譯: 使用 Pytest 進行 Python 測試:簡單、快速、有效且可擴展

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 編寫小型測試與擴展到應用程式、套件和庫的複雜功能測試一樣簡單。本書將向您展示如何做到這一點。

對於基於 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。