Skip to content

Exposes the underlining TestCase instance to avoid using "asserts" module #1191

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

kingbuzzman
Copy link
Contributor

@kingbuzzman kingbuzzman commented Apr 6, 2025

Related to issue: #1155

@kingbuzzman kingbuzzman marked this pull request as ready for review April 6, 2025 20:29
@kingbuzzman
Copy link
Contributor Author

@bluetech thoughts?

@bluetech
Copy link
Member

bluetech commented Apr 7, 2025

I have a (vain?) hope that someday pytest will be thread safe (i.e. specifically, it should be possible to run multiple pytest instances concurrently in the same process). Currently it isn't, and even pytest-django adds some issues itself. But I think it better to avoid adding new ones.

I think if we decide that's it worth putting effort into this issue, we should find a way to make the assert "bind" to the test it is running under. And if there's no clean way to do that, then consider an alternative interface which does make it possible (e.g. a django_assert fixture or such which binds to the current test via request and exposes the assertions as methods, e.g. django_assert.templateUsed()).

@kingbuzzman
Copy link
Contributor Author

But I think it better to avoid adding new ones.

This makes sense.

find a way to make the assert "bind" to the test it is running under.

I have some ideas on how to make this work

@kingbuzzman kingbuzzman marked this pull request as draft April 7, 2025 10:39
@kingbuzzman kingbuzzman changed the title Fixes issue with maxDiff and verbosity Exposes the underlining TestCase instance to avoid using "asserts" module Apr 7, 2025
@kingbuzzman
Copy link
Contributor Author

@bluetech what do you think of this approach?

@kingbuzzman kingbuzzman requested review from Copilot and adamchainz and removed request for Copilot April 7, 2025 13:26
@kingbuzzman kingbuzzman requested review from Copilot and bluetech April 7, 2025 13:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

pytest_django/fixtures.py:396

  • [nitpick] The type annotation for the _django_db_helper parameter is currently marked as None but it returns a TestCase instance (or None). Consider updating the annotation to accurately reflect the fixture's return type.
def django_testcase(_django_db_helper: None) -> django.test.TestCase | None:

pytest_django/asserts.py:36

  • [nitpick] Review the deprecation warning's stacklevel to ensure the warning points to the correct caller site for better traceability.
f'Use fixture "django_testcase" and django_testcase.{name} instead.'

@kingbuzzman kingbuzzman requested a review from Copilot April 7, 2025 14:38
Copilot

This comment was marked as off-topic.

@kingbuzzman kingbuzzman self-assigned this Apr 7, 2025
@kingbuzzman kingbuzzman marked this pull request as ready for review April 7, 2025 17:17
@kingbuzzman kingbuzzman requested a review from Copilot April 9, 2025 11:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • docs/helpers.rst: Language not supported

@kingbuzzman kingbuzzman requested a review from Copilot April 9, 2025 14:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • docs/helpers.rst: Language not supported
Comments suppressed due to low confidence (2)

pytest_django/fixtures.py:221

  • [nitpick] The fixture name 'django_testcase_class' might be ambiguous; consider renaming it to 'DjangoTestCaseClass' to clearly indicate that it returns a TestCase class.
def django_testcase_class(

pytest_django/asserts.py:34

  • [nitpick] The deprecation warning message could be made clearer by explicitly specifying the recommended usage of the 'django_testcase' fixture along with its attributes.
message = (

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

Successfully merging this pull request may close these issues.

2 participants