Django测试:在Travis CI上进行单独的单元和集成测试

时间:2022-10-15 23:50:13

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:

我有一个Django项目,该项目已经使用标准的Django测试框架进行了一些单元测试。这工作得很好。现在我想要和Travis CI建立集成测试,但是我碰到了几个阻滞剂:

  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. Django文档没有说明如何分离自包含的。来自集成测试的py测试单元测试,需要设置外部服务。我只想在我的dev机器和Travis CI上运行单元测试来运行单元测试和集成测试。我怎么把它们分开?
  3. 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?
  4. 我在Travis CI上的数据库中填充了在安装过程中填充的一些初始数据。我希望使用集成测试来运行,但是单元测试将继续使用临时测试数据库。我该怎么做呢?

1 个解决方案

#1


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.

1-你可以运行任何你想从管理。py测试命令。你可以创建一个unit_test文件。并且只在这个文件中运行测试。

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

2-你不想那样做。对生产/半生产数据库运行测试是一种耻辱。您需要为每个测试创建fixture,并对临时数据库运行测试。如果你真的想知道答案,这里已经有答案了

#1


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.

1-你可以运行任何你想从管理。py测试命令。你可以创建一个unit_test文件。并且只在这个文件中运行测试。

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

2-你不想那样做。对生产/半生产数据库运行测试是一种耻辱。您需要为每个测试创建fixture,并对临时数据库运行测试。如果你真的想知道答案,这里已经有答案了