Skip to content

Spike: ENP testing atomic transactions #190

Open
@kalbfled

Description

@kalbfled

User Story - Business Goal

  • Ticket is understood, and QA has been contacted (if the ticket has a QA label).

User Story(ies)

As a Notify developer,
I want test database transactions to be atomic by default
So that development is not unnecessarily impeded and I don't have an aneurysm.

Additional Info and Resources

A unit test that manipulates a database generally needs to rollback its changes so they don't affect other tests. In notification-api, we do this with factory fixtures that include teardown (example) and, unfortunately often, with manual teardown in the unit test code. This is laborious and somewhat error prone.

We want to avoid manual test isolation and clean-up with ENP testing. Some web application frameworks, like Django, have built-in support for atomic testing. notification-api, which runs on Flask, used to use a pytest add-on that made tests atomic. However, we removed it because it wasn't maintained and didn't necessarily play well with pytest-xdist, which is used to run tests concurrently.

What options do we have for FastAPI?

Acceptance Criteria & Checklist

  • Technical Documentation has been created and linked in the glossary
  • Learnings have been shared with the team, and decisions have been documented
  • Tickets for next steps have been identified and created

Completed research addresses the problems and/or answers the questions below:

  1. How can we implement unit testing in FastAPI in a way that is atomic? (Changes to the database are rolled back automatically after each test.)
  2. How do various options impact our ability to execute tests in parallel? For example, using pytest-xdist, which we use with notification-api.

Out of scope

Do not worry about preseeding the test database.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions