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

Test helpers #43

Open
samueljsb opened this issue Nov 27, 2024 · 0 comments
Open

Test helpers #43

samueljsb opened this issue Nov 27, 2024 · 0 comments

Comments

@samueljsb
Copy link
Contributor

I sometimes want to assert that a particular integrity error was raised during a test. At the moment I can do:

import pytest
from django.db.utils import IntegrityError

def test_():
    with pytest.raises(IntegrityError):
        ...

But, if I want to know which integrity error I'm catching, I need to either do some regexp matching on its message, or dig into the internals like this library does.

I'd love to be able to do:

from django_integrity import conversion, testing

def test_():
    with testing.raises(
        conversion.Unique(model=User, fields=("email",))
    ):
        ...

alternatives

I could also wrap the existing conversion code:

from django_integrity import conversion

def test_():
    class _MyIntegrityError(Exception):
        pass

   with (
        pytest.raises(_MyIntegrityError),
        conversion.refine_integrity_error(
            [(conversion.Unique(model=User, fields=("email",)), _MyIntegrityError)]
        ),
    ):
        ...

But that's a bit awkward. A helper for it would be so much easier to use.

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