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

Add pytest unit tests #251

Merged
merged 9 commits into from
Oct 9, 2024
Merged

Add pytest unit tests #251

merged 9 commits into from
Oct 9, 2024

Conversation

pederhan
Copy link
Member

@pederhan pederhan commented May 30, 2024

This PR adds Pytest unit tests which aim to complement the test suite by testing parts of the code that the integrations tests don't cover well (or at all).

Refactored TokenFile

The TokenFile class has been refactored to make it easier to test. This includes making certain methods public, and changing some methods from class methods to instance methods.

Furthermore, a TypeAdapter has been added to validate the contents of the token file. Following the precedent set by the existing methods, failed validation only prints an error instead of raising an exception.

Inline Snapshots

In order to save time on writing tests, the inline-snapshot package has been used to generate snapshots of values we test against. The usage of this should be documented, but the TL;DR is:

When writing a new test

pytest --inline-snapshot=review

One can also skip the diff view and create snapshots without previewing the changes:

pytest --inline-snapshot=create

NOTE: It's recommended to always use --inline-snapshot=review to see a diff of any modifications.

Fixing failing tests

To update a test after changing something that causes it to fail:

pytest --inline-snapshot=fix

# OR to interactively fix:

pytest --inline-snapshot=review

@pederhan pederhan changed the base branch from master to migrate_to_pydantic May 30, 2024 08:57
@pederhan pederhan marked this pull request as draft May 30, 2024 09:02
@pederhan pederhan changed the base branch from migrate_to_pydantic to make-testsuite-work-again-202405 June 12, 2024 08:58
@pederhan pederhan changed the base branch from make-testsuite-work-again-202405 to migrate_to_pydantic June 12, 2024 08:59
Base automatically changed from migrate_to_pydantic to master October 8, 2024 10:42
@pederhan pederhan marked this pull request as ready for review October 9, 2024 09:45
@pederhan pederhan requested a review from terjekv October 9, 2024 09:48
Copy link
Collaborator

@terjekv terjekv left a comment

Choose a reason for hiding this comment

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

Great work, thanks!

@pederhan pederhan merged commit 63ea4a3 into master Oct 9, 2024
12 checks passed
@pederhan pederhan deleted the pytest-unit-tests branch October 9, 2024 11:53
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