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.