Skip to content

Minor changes to support pytest #2675

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

Merged
merged 1 commit into from
May 25, 2024
Merged

Minor changes to support pytest #2675

merged 1 commit into from
May 25, 2024

Conversation

ankith26
Copy link
Member

A pleasant surprise: pytest seems to support unittest based tests out of box!

We've had occasional problems due to our custom test runner, and it seems like in the long term it's worth migrating to a tried and tested tool that handles stuff for us. The good part is that (after this PR) pytest test -k "not interactive" will be an alternate way of running tests that behaves like python -m test when running from the project directory, and the old machinery will still be default, and continue to work.

This PR is is needed because:

  1. pytest does not understand our custom tags system. But pytest allows enabling/skipping tests based on patterns in the name. So interactive tests need to be explicitly marked as so in the name
  2. pytest seems to run everything that begins with test_, so things that are not actually tests need a name changing
  3. There was one package import that works better as a relative import

Future work

  1. Make python3 -m pygame.tests/python3 -m test internally invoke pytest, maybe initially this should be controlled by an opt-in flag, but eventually it could be default
  2. write any new tests in pytest
  3. (optional) can incrementally port existing tests to pytest

@ankith26 ankith26 requested a review from a team as a code owner January 17, 2024 10:57
Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Simple changes.

I use pytest where I can on every python project that isn't pygame so this should be helpful.

@Starbuck5
Copy link
Member

Why do we want to support pytest? I know it's related to the unit test runner not reporting helpful results when something segfaults, but what exactly does pytest do for us in that vein?

@ankith26
Copy link
Member Author

pytest would not give that unhelpful error, and instead it should straight up give up at the segfault and report it exactly

@ankith26 ankith26 added this to the 2.5.0 milestone Apr 4, 2024
Copy link
Member

@zoldalma999 zoldalma999 left a comment

Choose a reason for hiding this comment

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

LGTM!

I don't see why we wouldn't support pytest as long as the old way works as well

@ankith26 ankith26 merged commit be47901 into main May 25, 2024
@ankith26 ankith26 deleted the ankith26-pytest branch May 25, 2024 18:23
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.

4 participants