1

I integrated travis in to my project where i used postgres but when i tried to test i got stuck in with an unkwown error i.e

 $ 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.

I used postgres format as below in .travis.yml file

 services:
  - mongodb
  - postgresql

 before_script:
  - sleep 15
  - psql -c 'create database myapp_test;' -U postgres

What i will do?

Dev
  • 31
  • 5

1 Answers1

0

From Django's source code, TEST_DATABASE_PREFIX is defined at line 12.

TEST_DATABASE_PREFIX = 'test_'

That means self.connection.settings_dict['NAME'] is None

From Django's document, you need to setup test db in your settings file like

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'USER': 'mydatabaseuser',
    'NAME': 'mydatabase',
    'TEST': {
        'NAME': 'mytestdatabase',   <--- YOU NEED CONFIG HERE!
    },
},
renqHIT
  • 174
  • 1
  • 10
  • I am getting something like this and after someting its failing ====>Creating test database for alias 'default'... Got an error creating the test database: database "mytestdatabase" already exists Type 'yes' if you would like to try deleting the test database 'mytestdatabase', or 'no' to cancel: – Dev Feb 13 '20 at 16:23
  • The settings is your choice. If you use test database only once, choose yes. By the way, it's recommended to change the default database name 'mytestdatabase' to your configuration. – renqHIT Feb 14 '20 at 02:35