Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Add support to specify db suffix from command line #1038

Open
gmuj opened this issue Dec 7, 2022 · 0 comments
Open

Idea: Add support to specify db suffix from command line #1038

gmuj opened this issue Dec 7, 2022 · 0 comments

Comments

@gmuj
Copy link

gmuj commented Dec 7, 2022

I am working on a big project which has a lot of migrations and I am bouncing from one branch to another where there will be differences between migrations (eg develop vs master). So sometimes I cannot reuse the existing test database when I checkout a different branch.

So my thought was to add a specific db suffix that can be used to specify different test db (based on my branch). The following code did the trick:

from pytest_django.fixtures import _set_suffix_to_test_databases
from pytest_django.lazy_django import skip_if_no_django

 def pytest_addoption(parser) -> None:
    """pytest django plugin enhancements.
    Adds pytest command line argument to specify test database suffix.
    """
    group = parser.getgroup("django")
    group.addoption(
        "--db-suffix",
        action="store",
        dest="db_suffix",
        default=None,
        help="Use specific test database suffix.",
    )


@pytest.fixture(scope="session")
def django_db_suffix(request) -> str:
    return request.config.getvalue("db_suffix")


@pytest.fixture(scope="session", autouse=True)
def django_db_modify_db_settings_config_suffix(django_db_suffix) -> None:
    skip_if_no_django()

    if django_db_suffix:
        _set_suffix_to_test_databases(suffix=django_db_suffix)

I was wondering if this can be added to that library and help others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant