-
-
Notifications
You must be signed in to change notification settings - Fork 41
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 Unit Testing Workflow using PyTest #400
Conversation
heroic_game[i].title = name | ||
|
||
for i in range(10): | ||
assert get_random_game_name(steam_app) in names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is just "regular" Python code, but PyTest will read and run these functions, and collate the rest results, tell you where certain tests fell over and why (e.g. expected X list of values, got Y). Is that right?
That means for "basic" tests there is not always a requirement to import or use anything from PyTest? There is probably some specific PyTest stuff for mocking and such, but it was interesting to me to see this as just simple Python code! That would be a big question mark I had around unit testing out of the way...
I'm definitely hoping to learn a lot more about PyTest and to go back and write unit tests for the code I've contributed, so figured I'd ask here 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is just "regular" Python code, but PyTest will read and run these functions, and collate the rest results, tell you where certain tests fell over and why (e.g. expected X list of values, got Y). Is that right?
That means for "basic" tests there is not always a requirement to import or use anything from PyTest?
That is correct.
PyTest imports are only required for e.g. fixtures which provide reliable/constant example data.
It will look for files prefixed with test_
by default.
I'm definitely hoping to learn a lot more about PyTest and to go back and write unit tests for the code I've contributed, so figured I'd ask here 😄
I have the same goal. I've worked with tools like Vitest before but I'm also new to PyTest 😄
There are also a few things I still need to figure out. For example, I'm calling the assert
statement 30 times. I've seen that (with Java I think) and it definitively works as it will just throw an AssertionError
in case the parameter is False
. But I don't know yet whether that is the correct/best way to do so.
Woohoo, once v2.10.0 is out and I get some of the ideas I have off my plate (I have some planned PRs for the near-ish future), I'll definitely see about submitting unit tests! |
Do we need to add PyTest as a dependency in |
Good question. Following what I read online, we may create a |
It looks like PyTest has a lot of plugins, some of which we might find useful.
Outside of that, we may also want to use requests-mock, or alternatively the responses library - I would probably lean towards using Adding all of these all at once may not make much sense, but in order to make sure these are available on a user's machine (so they don't have to hunt through the code to see what we might be importing, especially as the test suite get more robust) and in order to make sure our test dependencies are available on CI, it could be an idea to make a |
Good to know.
Ah, wasn't aware of responses. Seems to be the one which is used more often (4.1k stars and 24M downloads per month).
Yes, we should create that file and add dependencies one by one when we need them. |
Fix #347
pytest
util.py#get_random_game_name
Fixed Qt import for PyTest by installing libEGL and libxcbcommon and setting QT_QPA_PLATFORM=offscreen
Previously: Currently fails due to missing
libEGL
, i.e. the runner is headless but the Qt imports expect a graphics library. I will investigate that.