You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the async with blocks that are present in each test function. You're performing the same POST request in these blocks within a number of functions (test_create_user, test_invalid_create_user, test_login, test_invalid_login, etc).
First, you might create a helper function that handles these POST requests:
The creation of a new user is a good candidate for a helper function because it's a multi-step process that you're likely doing in multiple places within your tests. Here's what a helper function for that could look like:
Another problem is the current setup of the session. On every test, the database is being created and thrown out. This needs to be improved with a session scope. Most likely I will need to update the fixtures to handle existing data in the database
Consider the
async with
blocks that are present in each test function. You're performing the same POST request in these blocks within a number of functions (test_create_user
,test_invalid_create_user
,test_login
,test_invalid_login
, etc).First, you might create a helper function that handles these POST requests:
Now you can use
make_post_request
in your tests:The creation of a new user is a good candidate for a helper function because it's a multi-step process that you're likely doing in multiple places within your tests. Here's what a helper function for that could look like:
Now, the
test_create_user
function becomes:This kind of refactoring helps to keep your test code DRY and makes your tests less complex and more readable.
The text was updated successfully, but these errors were encountered: