Skip to content

test_util: Parametrize some tests #528

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

Conversation

sonic2kk
Copy link
Contributor

@sonic2kk sonic2kk commented Apr 11, 2025

This PR refactors two tests in test_util - test_get_dict_key_from_value and test_get_launcher_from_installdir - to use PyTest's parametrize feature. The rationale here is that instead of constructing test data inside of the tests for all different scenarios (in this case, many different launcher scenarios), we can instead pass in a list of scenarios to test.

For example in test_get_launcher_from_installdir, we pass in the Steam launcher list, then the Lutris launcher list, etc, and then for each of the scenarios passed in, the test will run against those without us having to define all of that logic. This allows the test itself to be lean and generic. This also makes it easy to add additional scenarios.

We can even name these scenarios using an id, so that when we run tests we can see the exact parametrized scenario. Previously we wouldn't have had any insight, whereas now if one parametrized test fails we can see the name (ID) of the failed test.


Note that test_get_random_game_name was left out of this, as we'd probably want in future to have some kind of PyTest fixture for games from each launcher that we can re-use. So for now the implementation was left alone :-)


I pushed for testing in general in ProtonUp-Qt, and I've been slacking. I've been trying to find the best pattern to go with for writing and thus submitting tests, and have been trying to learn as much as I can about writing "good" tests so that we can end up with a robust test suite that will give us confidence in that green "tick".

Hopefully this is a good first step in improving our tests and giving a good pattern on writing tests going forward. I'm already looking into writing some tests for the non-happy-path scenarios for the existing tests, and expanding the test suite. But that will come at a later date. 😉

Thanks!

@sonic2kk
Copy link
Contributor Author

sonic2kk commented Apr 23, 2025

I found a way to parametrize get_random_game_name, so I will push that to this branch in a sec :-)

I also added test cases for a few additional scenarios (making sure we get back a str value always, and ensuring we properly handle empty lists and unknown objects)

Accidentally pushed to a new branch, oops... Will just open as a separate PR :-)

@sonic2kk sonic2kk force-pushed the refactor-testutil-use-parametrize branch from e285796 to 3b6f6fe Compare April 24, 2025 20:24
@DavidoTek DavidoTek merged commit 9a585ba into DavidoTek:main May 5, 2025
2 checks passed
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