Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Crafting Test-Driven Software with Python

You're reading from   Crafting Test-Driven Software with Python Write test suites that scale with your applications' needs and complexity using Python and PyTest

Arrow left icon
Product type Paperback
Published in Feb 2021
Publisher Packt
ISBN-13 9781838642655
Length 338 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alessandro Molina Alessandro Molina
Author Profile Icon Alessandro Molina
Alessandro Molina
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Section 1: Software Testing and Test-Driven Development
2. Getting Started with Software Testing FREE CHAPTER 3. Test Doubles with a Chat Application 4. Test-Driven Development while Creating a TODO List 5. Scaling the Test Suite 6. Section 2: PyTest for Python Testing
7. Introduction to PyTest 8. Dynamic and Parametric Tests and Fixtures 9. Fitness Function with a Contact Book Application 10. PyTest Essential Plugins 11. Managing Test Environments with Tox 12. Testing Documentation and Property-Based Testing 13. Section 3: Testing for the Web
14. Testing for the Web: WSGI versus HTTP 15. End-to-End Testing with the Robot Framework 16. About Packt 17. Other Books You May Enjoy

To get the most out of this book

You will need a recent version of Python 3 and pip (the package installer for Python).

All code examples in this book have been tested using Python 3.7, 3.8, and 3.9 on Linux. However, they should work on other systems too. PyTest 6.0.2 was used by the examples that rely on PyTest.

Software/hardware covered in the book

OS requirements

Python 3.7, 3.8, or 3.9

Windows, MacOSX, or Linux (any)

pip 18+

PyTest 6.0.2+


Additional packages and libraries will be installed from the Python Package Index (
PyPI) using pip over the course of the chapters.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Crafting-Test-Driven-Software-with-Python. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The test prepares a dbpath object for the sole purpose of checking that dbmanager is asked to load that specific path."

A block of code is set as follows:

    def test_load(self):
dbpath = Path(tempfile.gettempdir(), "something")
dbmanager = Mock(
load=Mock(return_value=["buy milk", "buy water"])
)
app = TODOApp(io=(Mock(return_value="quit"), Mock()),
dbpath=dbpath, dbmanager=dbmanager)

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    def run(self):
self._quit = False
while not self._quit:
self._out(self.prompt(self.items_list()))
command = self._in()
self._dispatch(command)
self._out("bye!\n")

def items_list(self):
enumerated_items = enumerate(self._entries, start=1)
return "\n".join(
"{}. {}".format(idx, entry) for idx, entry in enumerated_items
)

Any command-line input or output is written as follows:

$ pip install pytest pytest-bdd

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Warnings or important notes appear like this.
Tips and tricks appear like this.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $24.99/month. Cancel anytime