Chapter 22. Test Fixtures and a Decorator for Explicit Waits
Now that we have a functional authentication system, we want to use it to identify users, and to show them all the lists they have created.
To do that, we’re going to have to write FTs that have a logged-in user. Rather than making each test go through the (time-consuming) login email dance, we want to be able to skip that part.
This is about separation of concerns. Functional tests aren’t like unit tests, in that they don’t usually have a single assertion. But, conceptually, they should be testing a single thing. There’s no need for every single FT to test the login/logout mechanisms. If we can figure out a way to “cheat” and skip that part, we’ll spend less time waiting for tests to repeat these duplicated setup steps.
Tip
Don’t overdo de-duplication in FTs. One of the benefits of an FT is that it can catch strange and unpredictable interactions between different parts of your application.
In this short chapter, we’ll start writing our new FT, and use that as an opportunity to talk about de-duplication using test fixtures for FTs. We’ll also refactor out a nice helper for explicit waits, using Python’s lovely decorator syntax.
Skipping the Login Process by Pre-creating a Session
It’s quite common for a user to return to a site and still have a cookie, which means they are “pre-authenticated”, so this isn’t an unrealistic cheat at all. Here’s how you can set it up:
src/functional_tests/test_my_lists.py (ch22l001) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access