In regards to fixtures, I think it would have been useful to see an example in which your custom fixture actually yields. This way you could show setup and teardown scenarios similar to what unittest does.
as a physics undergrad this really helps me in my coding courses cause they threw us in cold water with that stuff! Thanks and cheers from austria aka Vienna != Austria hehe
Hi Matt, thanks so much for these videos, they're a really good primer! I've got a couple of questions if you've got a moment or two: Are the fixtures the only arguments that test functions would ever take? If there are other arguments, then on what basis does pytest distinguish between the fixture arguments and the non-fixture arguments? You mentioned that you can have multiple files that store your fixtures at 26:38. How does pytest look for these files? E.g. Is there naming convention? Thanks again!
Most test functions won't take any arguments so this usually isn't an issue. That being said, there are a couple of cases that pytest can handle. 1. If you have test classes with test methods, pytest will ignore the self parameter. 2. If you are using mock.patch as a decorator, the mocked object will be the first argument. pytest will happily ignore it and fixtures can coexist with the mocked parameter. 3. If it's not either of those cases and you typo the name of the fixture, pytest will complain saying it can't find the fixture. For multiple fixture files, pytest looks for files named conftest.py. The root conftest.py are fixtures that are available across the entire suite. If you want fixtures that are only scoped to a certain package, then you can put a conftest.py in that package. The fixtures in that package will only be available to that package (and any sub-packages). I hope that makes sense. Thanks for the questions!
Thanks for sharing. It is really useful. I'm just curious, if I have a method that relies on API to get the json data then run its computation. Do I just store the data as a variable in the test file or is there other better option. So that I do not need to query the API for the testing.
Check out vcrpy.readthedocs.io/en/latest/index.html or betamax.readthedocs.io/en/latest/index.html. Those are tools to record API requests that can be used to avoid going to real APIs all the time.
9:27 Testing exceptions/errors
13:20 Parametrize
24:08 Fixtures
28:10 Built-in pytest fixtures
Wow.. I just watched your 101 and I was wondering about this one and voilà!.. Thx Matt for these greats contents. Keep up with the good work!
This and the 101 video are a great introduction to pytest, thank you very much for making them available!
Your 101 and 201 video helped me a lot. Thank you for sharing this.
Glad it helped!
Great talks on pytest. Enjoyed both pytest 101 and pytest 201 very much.
In regards to fixtures, I think it would have been useful to see an example in which your custom fixture actually yields. This way you could show setup and teardown scenarios similar to what unittest does.
Nice talk! Thanks for posting it!
as a physics undergrad this really helps me in my coding courses cause they threw us in cold water with that stuff! Thanks and cheers from austria aka Vienna != Austria hehe
Awesome! I'm glad it helped.
Hi Matt, thanks so much for these videos, they're a really good primer! I've got a couple of questions if you've got a moment or two:
Are the fixtures the only arguments that test functions would ever take? If there are other arguments, then on what basis does pytest distinguish between the fixture arguments and the non-fixture arguments?
You mentioned that you can have multiple files that store your fixtures at 26:38. How does pytest look for these files? E.g. Is there naming convention?
Thanks again!
Most test functions won't take any arguments so this usually isn't an issue. That being said, there are a couple of cases that pytest can handle.
1. If you have test classes with test methods, pytest will ignore the self parameter.
2. If you are using mock.patch as a decorator, the mocked object will be the first argument. pytest will happily ignore it and fixtures can coexist with the mocked parameter.
3. If it's not either of those cases and you typo the name of the fixture, pytest will complain saying it can't find the fixture.
For multiple fixture files, pytest looks for files named conftest.py. The root conftest.py are fixtures that are available across the entire suite. If you want fixtures that are only scoped to a certain package, then you can put a conftest.py in that package. The fixtures in that package will only be available to that package (and any sub-packages).
I hope that makes sense. Thanks for the questions!
@@MattLayman Amazing, yep that all makes sense:). Cheers for the detailed reply!
Thanks a lot ! Should I expect future session on Hooks? !
That's an interesting suggestion, thanks. It's not in plan currently, but if I do another pytest video, that seems like a good topic to cover.
Great video for pytest beginners!!
Thanks for sharing. It is really useful. I'm just curious, if I have a method that relies on API to get the json data then run its computation. Do I just store the data as a variable in the test file or is there other better option. So that I do not need to query the API for the testing.
Check out vcrpy.readthedocs.io/en/latest/index.html or betamax.readthedocs.io/en/latest/index.html. Those are tools to record API requests that can be used to avoid going to real APIs all the time.
Great tutorial!!
omg... dont get me started on nesting functions... i havent done that in ages...
very useful information. i really appreciated
-.- why is everything college or university... now im saying it too...