Giter Site home page Giter Site logo

claytonseraphin / factory-boy-best-practices Goto Github PK

View Code? Open in Web Editor NEW

This project forked from camilamaia/factory-boy-best-practices

0.0 0.0 0.0 105 KB

factory_boy best practices

License: MIT License

Python 94.52% CSS 0.08% Makefile 0.41% HTML 4.99%

factory-boy-best-practices's Introduction

factory_boy Best Practices

  1. Factories should represent their models

  2. Do not rely on defaults from factories

    • 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
  3. Factories should contain only the required data

    • If the field is nullable (null=True) the attribute should be under a trait and not as a default value
    • If we want to have explicitly the attribute, we can use MyFactory(with_myattr=True)
    • When are we going to remember to test the case MyFactory(myattr=None)?
    • We should not assume there is an author when DB actually allows to not have it.
  4. Build over create

    • MyFactory.build(): creates a local object (memory)
    • MyFactory.create(): creates a local object + stores it in the DB
  5. If FK is in the table: SubFactor

    If FK is in the other table: RelatedFactory + trait

    • SubFactory: builds/creates the SubFactory during the process of creation of the main factory
    • RelatedFactory: builds/creates the RelatedFactory after creating the main factory
  6. Use fixtures to wrap factories to avoid duplication

  7. Avoid sharing factories or fixtures among different files

  8. get_or_create should be used only for unique keys

factory-boy-best-practices's People

Contributors

camilamaia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.