Page MenuHomeSoftware Heritage
Paste P937

pytest-postgresql recursive dependency
ActivePublic

Authored by vlorentz on Feb 3 2021, 2:31 PM.
$ cat /home/dev/swh-environment/swh-storage/swh/storage/tests/test_postgresql_migration.py
# Copyright (C) 2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import glob
import os
import subprocess
import attr
import pytest
from pytest_postgresql import factories
from swh.core.db.pytest_plugin import postgresql_fact
from swh.core.utils import numfile_sortkey as sortkey
from swh.storage import get_storage
DIR = os.path.dirname(__file__)
my_postgresql = factories.postgresql(
"my_postgresql",
load=glob.glob(os.path.join(DIR, "data", "sql-v0.18.0", "*.sql"))
)
@pytest.fixture
def storage(my_postgresql):
config = {
"db": my_postgresql.dsn,
"check_config": False, # it would error on the dbversion number
}
return get_storage(**config)
class TestPgStorageMigration:
"""Creates an old schema, inserts some data, runs migrations, and checks the
data still exists."""
def test_(self, storage):
pass
$ pytest -k migration -vv -s
==================================================================== test session starts =====================================================================
platform linux -- Python 3.7.3, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/dev/swh-environment/swh-storage/.hypothesis/examples')
rootdir: /home/dev/swh-environment/swh-storage, configfile: pytest.ini
plugins: parallel-0.0.10, django-3.7.0, forked-1.1.3, kafka-0.4.0, postgresql-2.5.3, cov-2.10.0, dash-1.12.0, celery-4.4.0, mock-1.13.0, xdist-1.31.0, testinfra-4.0.0, hypothesis-5.49.0, swh.core-0.10.0, swh.journal-0.6.1.dev3+g5f7e433, requests-mock-1.5.2
collected 761 items / 760 deselected / 1 selected
swh/storage/tests/test_postgresql_migration.py::TestPgStorageMigration::test_ ERROR
=========================================================================== ERRORS ===========================================================================
_______________________________________________________ ERROR at setup of TestPgStorageMigration.test_ _______________________________________________________
file /home/dev/swh-environment/swh-storage/swh/storage/tests/test_postgresql_migration.py, line 39
def test_(self, storage):
file /home/dev/swh-environment/swh-storage/swh/storage/tests/test_postgresql_migration.py, line 27
@pytest.fixture
def storage(my_postgresql):
file /home/dev/.local/lib/python3.7/site-packages/pytest_postgresql/factories.py, line 230
@pytest.fixture
def postgresql_factory(request: FixtureRequest) -> connection:
E recursive dependency involving fixture 'my_postgresql' detected
> available fixtures: _dj_autoclear_mailbox, _django_clear_site_cache, _django_db_marker, _django_set_urlconf, _django_setup_unittest, _fail_for_invalid_template_variable, _live_server_helper, _push_request_context, _template_string_if_invalid_marker, _testinfra_host, admin_client, admin_user, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, celery_app, celery_config, celery_enable_logging, celery_includes, celery_parameters, celery_session_app, celery_session_worker, celery_worker, celery_worker_parameters, celery_worker_pool, client, consumer, cov, dash_br, dash_duo, dash_process_server, dash_thread_server, dashr, dashr_server, datadir, db, depends_on_current_app, django_assert_max_num_queries, django_assert_num_queries, django_db_blocker, django_db_createdb, django_db_keepdb, django_db_modify_db_settings, django_db_modify_db_settings_parallel_suffix, django_db_modify_db_settings_tox_suffix, django_db_modify_db_settings_xdist_suffix, django_db_reset_sequences, django_db_setup, django_db_use_migrations, django_mail_dnsname, django_mail_patch_dns, django_test_environment, django_user_model, django_username_field, doctest_namespace, flask_app_client, host, kafka_consumer_group, kafka_prefix, kafka_server, kafka_server_base, live_server, mailoutbox, mock, mocker, monkeypatch, my_postgresql, no_cover, object_types, postgresql, postgresql_nooproc, postgresql_proc, privileged_object_types, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, requests_mock, requests_mock_datadir, requests_mock_datadir_visits, rf, sample_data, session_tmpdir_path, settings, storage, swh_contents, swh_origins, swh_rpc_adapter, swh_rpc_client, swh_storage, swh_storage_backend_config, swh_storage_postgresql, test_config, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory, tmpdir_path, transactional_db, use_celery_app_trap, worker_id
> use 'pytest --fixtures [testpath]' for help on them.
/home/dev/.local/lib/python3.7/site-packages/pytest_postgresql/factories.py:230
================================================================== short test summary info ===================================================================
ERROR swh/storage/tests/test_postgresql_migration.py::TestPgStorageMigration::test_
============================================================== 760 deselected, 1 error in 1.01s ==============================================================

Event Timeline

vlorentz changed the title of this paste from untitled to pytest-postgresql recursive dependency.
vlorentz updated the paste's language from autodetect to python.

Maybe?

from pytest_postgresql import factories

from swh.core.db.pytest_plugin import postgresql_fact

Use postgresql_fact factory from swh.core.db... instead of factories (and drop the import)? (also don't know if you care but postgresql_fact does truncate in between test and not plain old destroy/create dance the other does).

From:

my_postgresql = factories.postgresql(

to:

my_postgresql = postgresql_fact(

nah the issue was the name on line 23