Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
pytest Quick Start Guide

You're reading from   pytest Quick Start Guide Write better Python code with simple and maintainable tests

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789347562
Length 160 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Bruno Oliveira Bruno Oliveira
Author Profile Icon Bruno Oliveira
Bruno Oliveira
Arrow right icon
View More author details
Toc

Tips/discussion

The following are some short topics and tips that did not fit into the previous sections, but that I think are worth mentioning.

When to use fixtures, as opposed to simple functions

Sometimes, all you need is to construct a simple object for your tests, and arguably this can be done in a plain function, not necessarily needing to be implemented as a fixture. Suppose we have a WindowManager class, that does not receive any parameters:

class WindowManager:
...

One way to use it in our tests would be to write a fixture:

@pytest.fixture
def manager():
return WindowManager()

def test_windows_creation(manager):
window = manager.new_help_window("pipes_help.rst")
assert window.title() == &quot...
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 $19.99/month. Cancel anytime
Banner background image