2

I have a Django project that already has some unit tests using the standard Django testing framework. That works well. Now I want to set up integration tests with Travis CI, but I'm hitting several blockers:

  1. Django docs don't say how to separate self-contained ./manage.py test unit tests from the integration tests, that require external services to be set up. I want to only run unit tests on my dev machine and Travis CI to run both unit and integration tests. How do I separate these?
  2. I have the database on Travis CI filled with some initial data populated during the setup. I want integration tests to run with that, but unit tests to continue using a temporary test-only DB. How do I do that?

1 Answers1

1

1- You can run any test you want from the manage.py test command. So you can create a file unit_test.py and run only the tests inside this file.

manage.py test --help

2- You don't want to do that. Run test against a production/semi-production database is a shame. You need to create fixtures for every tests, and run your tests against a temporary database. If you really want to know the answer, it has already been answered here

Community
  • 1
  • 1
FlogFR
  • 729
  • 7
  • 14
  • 1
    When writing unit tests, you really don't to test against a production database. But when running integration tests (as in Travis CI), your production database IS your test database. When you test integration with external tools that might also modify/interact with the database, you want to be using the "production" database. – Ivailo Karamanolev Sep 06 '14 at 18:48