Closed ryaustin closed 12 months ago
As I work on this I'm following the model of the previous two tests and am wondering about code repetition. It looks like each test starts from 0, i.e. it has to create the user, create the tune, etc. Is it possible to make this a little more modular by having say a create_user function, create_tune function so that the tests don't end up being so repetitive? Or is this not really a concern with tests?
This is where fixtures come into play: https://pybit.es/articles/pytest-fixtures - they allow you to write repeated set up code.
Related @ryaustin clinic on Factory boy (might not need yet but good to know!) https://pybites.circle.so/c/pybites-coaching-calls/sections/117462/lessons/394723
Seems you struggled a bit with setup you said @jwjacobson so here is a reference video just in case: https://www.youtube.com/watch?v=L5jWFU2sVXQ
Good on you for recognizing all that repetition @jwjacobson. Fixtures are your key tool here and Bob provided some great resources above. Fixtures are fine to move into now since the repetition is already a concern of yours but I'd recommend you not worry too much about optimizing everything just yet. Get into the habit of writing tests & understanding the code you have to maintain, optimizing will come.
Follow the pattern we used today to write a test for Tune Edit: