Skip to content

Migrate tests to pytest paradigm#813

Merged
azmeuk merged 8 commits intoauthlib:mainfrom
azmeuk:pytest-paradigm
Sep 6, 2025
Merged

Migrate tests to pytest paradigm#813
azmeuk merged 8 commits intoauthlib:mainfrom
azmeuk:pytest-paradigm

Conversation

@azmeuk
Copy link
Member

@azmeuk azmeuk commented Sep 1, 2025

What kind of change does this PR introduce?

This migrates all the tests from the unittest paradigm to the pytest paradigm:

  • Use pytest fixtures instead of setUp/tearDown. This allowed a bit of factorization.
  • Use test functions instead of TestCase classes.
  • Long test files have been split.
  • Django and Flask authorization server config loading part has been moved to dedicated load_config methods.

This makes the unit tests a lot more legible, and a bit shorter. There are still 748 tests as before.

Follow-up to #746

Checklist

  • The commits follow the conventional commits specification.
  • You ran the linters with prek.
  • You reached 100% of code coverage on the code you edited, without abusive use of pragma: no cover

  • You consent that the copyright of your pull request source code belongs to Authlib's author.

@azmeuk azmeuk requested a review from lepture September 1, 2025 12:16
create_resource_server(app, use_cache, use_cache)
url = "/user"

# case 1
Copy link

Choose a reason for hiding this comment

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

Suggestion: Instead of having case 1... case 5 all in one test, use pytest.mark.parametrize() to separate these into individual test cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like pytest parametrize, but in that particular case pytest it a bit overkill to me. There are 3 vars to parametrize (url, error, error_description) for a 4 lines test. Anyway, I think both solutions would be fine.
I did not put a lot of factorization effort into OAuth1, but feel free to open a PR if you want to work on this.

@azmeuk azmeuk changed the title Migrate Flask tests to pytest paradigm Migrate tests to pytest paradigm Sep 1, 2025
@lepture
Copy link
Member

lepture commented Sep 6, 2025

You don't need to migrate tests for jose module. Since we are going to remove jose module from authlib, we will also remove its tests.

@azmeuk
Copy link
Member Author

azmeuk commented Sep 6, 2025

You don't need to migrate tests for jose module.

I know but that was a really quick thing to do.
Do you prefer that I restore the way it was?

@azmeuk azmeuk merged commit 49d0f47 into authlib:main Sep 6, 2025
8 checks passed
@azmeuk azmeuk deleted the pytest-paradigm branch September 6, 2025 13:54
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.

3 participants