Description
I've taken a look at all the issues and #431 before. I'm somewhat new to pytest-django
since I mostly used regular unit tests. I noticed the age of that issue, though, and according to https://docs.djangoproject.com/en/3.0/topics/testing/tools/#django.test.TransactionTestCase.databases, it seems like it should be possible now? But how? It just seems confusing how or where I'd set the databases
value...
The error I get when running with a PostGIS and a PostgreSQL database (yes, using two different engines) is this:
―――――――――――――――――――――――― ERROR at setup of test_update ―――――――――――――――――――――――――
3373
3374request = <SubRequest '_django_db_marker' for <Function test_update>>
3375
3376 @pytest.fixture(autouse=True)
3377 def _django_db_marker(request):
3378 """Implement the django_db marker, internal to pytest-django.
3379
3380 This will dynamically request the ``db``, ``transactional_db`` or
3381 ``django_db_reset_sequences`` fixtures as required by the django_db marker.
3382 """
3383 marker = request.node.get_closest_marker("django_db")
3384 if marker:
3385 transaction, reset_sequences = validate_django_db(marker)
3386 if reset_sequences:
3387 request.getfixturevalue("django_db_reset_sequences")
3388 elif transaction:
3389 request.getfixturevalue("transactional_db")
3390 else:
3391> request.getfixturevalue("db")
3392
3393/usr/local/lib/python3.7/site-packages/pytest_django/plugin.py:499:
3394_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
3395/usr/local/lib/python3.7/site-packages/pytest_django/fixtures.py:108: in django_db_setup
3396 **setup_databases_args
3397/usr/local/lib/python3.7/site-packages/django/test/utils.py:173: in setup_databases
3398 serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
3399/usr/local/lib/python3.7/site-packages/django/db/backends/base/creation.py:72: in create_test_db
3400 run_syncdb=True,
3401/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py:168: in call_command
3402 return command.execute(*args, **defaults)
3403/usr/local/lib/python3.7/site-packages/django/core/management/base.py:369: in execute
3404 output = self.handle(*args, **options)
3405/usr/local/lib/python3.7/site-packages/django/core/management/base.py:83: in wrapped
3406 res = handle_func(*args, **kwargs)
3407/usr/local/lib/python3.7/site-packages/django/core/management/commands/migrate.py:233: in handle
3408 fake_initial=fake_initial,
3409/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py:117: in migrate
3410 state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
3411/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py:147: in _migrate_all_forwards
3412 state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
3413/usr/local/lib/python3.7/site-packages/django/db/migrations/executor.py:245: in apply_migration
3414 state = migration.apply(state, schema_editor)
3415/usr/local/lib/python3.7/site-packages/django/db/migrations/migration.py:124: in apply
3416 operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
3417/usr/local/lib/python3.7/site-packages/django/db/migrations/operations/models.py:92: in database_forwards
3418 schema_editor.create_model(model)
3419/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py:322: in create_model
3420 sql, params = self.table_sql(model)
3421/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py:159: in table_sql
3422 definition, extra_params = self.column_sql(model, field)
3423/usr/local/lib/python3.7/site-packages/django/db/backends/base/schema.py:212: in column_sql
3424 db_params = field.db_parameters(connection=self.connection)
3425/usr/local/lib/python3.7/site-packages/django/db/models/fields/__init__.py:715: in db_parameters
3426 type_string = self.db_type(connection)
3427_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
3428
3429self = <django.contrib.gis.db.models.fields.MultiPolygonField: polygon>
3430connection = <django.db.backends.postgresql.base.DatabaseWrapper object at 0x7f008e3938d0>
3431
3432 def db_type(self, connection):
3433> return connection.ops.geo_db_type(self)
3434E AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
3435
3436/usr/local/lib/python3.7/site-packages/django/contrib/gis/db/models/fields.py:105: AttributeError
3437
There was also some discussion in Django Dev of this being a syncdb issue for a geo and a non-geo database, but I'm having no trouble writing the code and testing it via the Django views... for now, of course.
I will admit, I haven't tried testing this with normal Django TestCase.