travis ci 在 django 和 postgres Github 中集成时出错
Error during travis ci integration in django and postgres in Github
我将 travis 集成到我使用 postgres 的项目中,但是当我尝试测试时,我遇到了未知错误,即
$ python manage.py test
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/commands/test.py", line 53, in handle
failures = test_runner.run_tests(test_labels)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/test/runner.py", line 629, in run_tests
old_config = self.setup_databases(aliases=databases)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/test/runner.py", line 554, in setup_databases
self.parallel, **kwargs
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/test/utils.py", line 157, in setup_databases
test_databases, mirrored_aliases = get_unique_databases_and_mirrors(aliases)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/test/utils.py", line 258, in get_unique_databases_and_mirrors
default_sig = connections[DEFAULT_DB_ALIAS].creation.test_db_signature()
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 295, in test_db_signature
self._get_test_db_name(),
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 153, in _get_test_db_name
return TEST_DATABASE_PREFIX + self.connection.settings_dict['NAME']
TypeError: must be str, not NoneType
The command "python manage.py test" exited with 1.
我在 .travis.yml 文件
中使用了如下的 postgres 格式
services:
- mongodb
- postgresql
before_script:
- sleep 15
- psql -c 'create database myapp_test;' -U postgres
我会做什么?
从 Django's source code 开始,TEST_DATABASE_PREFIX
在第 12 行定义。
TEST_DATABASE_PREFIX = 'test_'
这意味着 self.connection.settings_dict['NAME']
是 None
从 Django's document 开始,您需要在设置文件中设置测试数据库,例如
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'USER': 'mydatabaseuser',
'NAME': 'mydatabase',
'TEST': {
'NAME': 'mytestdatabase', <--- YOU NEED CONFIG HERE!
},
},
我将 travis 集成到我使用 postgres 的项目中,但是当我尝试测试时,我遇到了未知错误,即
$ python manage.py test
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/core/management/commands/test.py", line 53, in handle
failures = test_runner.run_tests(test_labels)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/test/runner.py", line 629, in run_tests
old_config = self.setup_databases(aliases=databases)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/test/runner.py", line 554, in setup_databases
self.parallel, **kwargs
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/test/utils.py", line 157, in setup_databases
test_databases, mirrored_aliases = get_unique_databases_and_mirrors(aliases)
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/test/utils.py", line 258, in get_unique_databases_and_mirrors
default_sig = connections[DEFAULT_DB_ALIAS].creation.test_db_signature()
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 295, in test_db_signature
self._get_test_db_name(),
File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/db/backends/base/creation.py", line 153, in _get_test_db_name
return TEST_DATABASE_PREFIX + self.connection.settings_dict['NAME']
TypeError: must be str, not NoneType
The command "python manage.py test" exited with 1.
我在 .travis.yml 文件
中使用了如下的 postgres 格式 services:
- mongodb
- postgresql
before_script:
- sleep 15
- psql -c 'create database myapp_test;' -U postgres
我会做什么?
从 Django's source code 开始,TEST_DATABASE_PREFIX
在第 12 行定义。
TEST_DATABASE_PREFIX = 'test_'
这意味着 self.connection.settings_dict['NAME']
是 None
从 Django's document 开始,您需要在设置文件中设置测试数据库,例如
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'USER': 'mydatabaseuser',
'NAME': 'mydatabase',
'TEST': {
'NAME': 'mytestdatabase', <--- YOU NEED CONFIG HERE!
},
},