- I have tests which require user to login
- For such tests I register new user
- Such tests also have user_logout function (right before assert)
The problem:
If tests fails somewhere prior to calling user_logout
and assertion, it breaks some of the following tests which require registration - the signup form by design is not available for logged in users, so the user registration flow fails because selenium can not find registration forms (no logout - kept user - session - no registration form).
I have two ideas how to prevent tests failing not because of assertion to affect the following tests:
- Add to the tests with login kind of flag 'requires_logout' and add some handler to the conftest.py with pytest_exception_interact
- pros: solution looks solidly and impressively
- cons: conftest will require import of UI tests handle lib to call user_logout there. Don't know why but I don't like it
- pros: solution looks solidly and impressively
- Wrap test itself in try-except until user_logout and assert and do an 'emergency' user_logout on any exception.
- pros: seems easy and reliable
- cons: doubts that it is proper usage of exceptions and tests framework; double user_logout call in test file (within try-except and 'regular' prior assert.
- pros: seems easy and reliable
- Within registration flow check if we're logged in and logout but someday I'll write tests to check that registration is not available for logged users.
What is the best way to handle this situation?