Upgrade to Pro — share decks privately, control downloads, hide ads and more …

factory_boy: testing like a pro. DjangoCon EU 2022

Camila Maia
September 22, 2022

factory_boy: testing like a pro. DjangoCon EU 2022

Camila Maia

September 22, 2022
Tweet

More Decks by Camila Maia

Other Decks in Technology

Transcript

  1. @cmaiacd 🧰 🛠 🔧 ⚙ Sequence Faker Fuzzy attributes LazyFunction

    LazyAttribute Inheritance Inheritance Params Traits Strategies RelatedFactory / SubFactory
  2. @cmaiacd The tests are created in a way to fit

    the factory factory-oriented testing
  3. @cmaiacd Model - Poll Poll Question Choice n:1 pub_date :

    DateTimeField premium : BooleanField author : CharField question_text : CharField language : CharField choice_text : CharField votes : IntegerField 1:1
  4. @cmaiacd • If a default value is changed, all tests

    that depend on it will break • The setup of a test should contain all the logic to ensure it will always pass • Explicit better than implicit
  5. @cmaiacd If the field is nullable (null=True) the attribute should

    be under a trait and not as a default value
  6. @cmaiacd If we want to have an author, we can

    use PollFactory(with_author=True) now When are we going to remember to test the case PollFactory(author=None)? We should not assume there is an author when DB actually allows to not have it.
  7. @cmaiacd BUILD STRATEGY ========== 14 passed in 1.76 seconds ==========

    CREATE STRATEGY ========== 14 passed in 3.26 seconds ==========
  8. @cmaiacd 5. IF FK IS IN THE TABLE: SUBFACTOR IF

    FK IS IN THE OTHER TABLE: RELATEDFACTORY + TRAIT
  9. @cmaiacd SubFactory: builds/creates the SubFactory during the process of creation

    of the main factory RelatedFactory: builds/creates the RelatedFactory after creating the main factory