be careful with the Django signals • mock external services (pytest-mock) • take advantage of concurrent execution (pytest-xdist) • reuse database from last run (pytest --reuse-db)
what are, IMHO, the two key features of pytest: ◦ fixtures: very easy way to inject the dependencies (mostly objects) you need in order to recreate your pre-test scenario ◦ parametrize: allow us to execute the same test with diferents parameters sets (use cases)
- gives access to the database • rf - request factory • client - test client • admin_client - authenticated test client • admin_user - authenticated superuser • settings - access to the django settings • mailoutbox - mailbox where to test the sending of emails
models very easily • field values are generated automatically • content random of the fields but can be specified individually • You can create objects: ◦ only in memory ( mommy.prepare ) useful for unit tests model methods ◦ persistent ( mommy.make ) useful for integration tests • you can define relationships between objects (fk, m2m) • you can define recipes, which are like set of objects related to each other • sequence fields can be defined • you can create data generators for a given type of field