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

Okken, Brian

  • 出版商: Pragmatic Bookshelf
  • 出版日期: 2022-03-29
  • 售價: $1,800
  • 貴賓價: 9.5$1,710
  • 語言: 英文
  • 頁數: 274
  • 裝訂: Quality Paper - also called trade paper
  • ISBN: 1680508601
  • ISBN-13: 9781680508604
  • 相關分類: Python程式語言JVM 語言
  • 立即出貨 (庫存=1)

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

商品描述

Test applications, packages, and libraries large and small with pytest, Python's most powerful testing framework. pytest helps you write tests quickly and keep them readable and maintainable. In this fully revised edition, explore pytest's superpowers - simple asserts, fixtures, parametrization, markers, and plugins - while creating simple tests and test suites against a small database application. 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. This book shows you how.

pytest is undeniably the best choice for testing Python projects. It's a full-featured, flexible, and extensible testing framework. pytest's fixture model allows you to share test data and setup procedures across multiple layers of tests. The pytest framework gives you powerful features such as assert rewriting, parametrization, markers, plugins, parallel test execution, and clear test failure reporting - 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 yet powerful tool. Write short, maintainable tests that elegantly express what you're testing. Speed up test times by distributing tests across multiple processors and running tests in parallel. Use Python's builtin assert statements instead of awkward assert helper functions to make your tests more readable. Move setup code out of tests and into fixtures to separate setup failures from 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, and even existing unittest tests.

Write simple, maintainable tests quickly with pytest.

What You Need:

The examples in this book were written using Python 3.9 and pytest 6. pytest 6 supports Python 3.5 and above.

商品描述(中文翻譯)

測試應用程式、套件和庫,無論大小,使用 pytest,Python 最強大的測試框架。pytest 幫助您快速編寫測試,並保持其可讀性和可維護性。在這本全面修訂的版本中,探索 pytest 的超能力 - 簡單的斷言、fixture、參數化、標記和插件 - 同時針對一個小型資料庫應用程式創建簡單的測試和測試套件。使用一個穩健而簡單的 fixture 模型,使用 pytest 編寫小型測試和擴展到複雜的功能測試一樣簡單。本書將告訴您如何做到這一點。

pytest 無疑是測試 Python 專案的最佳選擇。它是一個功能齊全、靈活且可擴展的測試框架。pytest 的 fixture 模型允許您在多層測試中共享測試數據和設置程序。pytest 框架提供了強大的功能,如斷言重寫、參數化、標記、插件、並行測試執行和清晰的測試失敗報告 - 無需樣板代碼。

本書提供簡單的逐步指導和範例代碼,讓您快速掌握這個易於學習但功能強大的工具。編寫簡短、可維護的測試,優雅地表達您正在測試的內容。通過在多個處理器上分配測試並並行運行測試來加快測試時間。使用 Python 的內建斷言語句,而不是笨拙的斷言輔助函數,使您的測試更具可讀性。將設置代碼移出測試並放入 fixture 中,以將設置失敗與測試失敗分開。使用預期異常測試來測試錯誤條件和邊界情況,並使用參數化測試來用一個測試運行多個測試案例。通過插件擴展 pytest,將其連接到持續集成系統,並與 tox、mock、coverage 甚至現有的 unittest 測試一起使用。

快速編寫簡單、可維護的測試,使用 pytest。

您需要的內容:

本書中的範例是使用 Python 3.9 和 pytest 6 編寫的。pytest 6 支援 Python 3.5 及以上版本。

作者簡介

Brian Okken is the host of the Test & Code podcast, and co-host of the Python Bytes podcast. He's also a lead software engineer.

作者簡介(中文翻譯)

Brian Okken 是 Test & Code 播客的主持人,也是 Python Bytes 播客的共同主持人。他還是一名首席軟體工程師。