Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running integration tests separately from unit tests in django

The convention for creating tests in django is to place tests in modules named tests_*.py and to run then as python manage.py test.

This will run all tests defined tests in all modules named tests.

The challenge I have come across is that integration tests may require significant setup of resources e.g. connection to external services. I would imagine mocking out those services in integration tests would cause integration tests to loose their meaning.

I am inquiring therefore of the best practice in running only unit tests and only run integration tests when unit tests are running properly.

The only way I can imagine is to place integration tests in files named with a different pattern such as integration_*.py and then use the pattern parameter when running integration tests as specified by the django documentation

Like this python manage.py test --pattern="integration_*".

In this way when python manage.py test is called integration tests will be ignored.

Does anyone have a suggestion or recommendation.

like image 412
unlockme Avatar asked Oct 20 '25 01:10

unlockme


1 Answers

You can use Tagging test to handle this. Try to tag your test by a name then:

./manage.py test --tag=integration
like image 97
Toan Quoc Ho Avatar answered Oct 21 '25 13:10

Toan Quoc Ho