This is a great introduction which I'll be sending to my students now. :) Thanks!
@bigmacbeta2 ай бұрын
Learnt something new. Use yield instead of return with the context manager in a fuxture. Thank you, thank you, thank you.
@sudharsan4040 Жыл бұрын
One of the best pytest tutorial. Can you please put a tutorial on mocking nested pytest classes and patching them. An excellent use case like using Azure or AWS python sdk
@aneeszuberi1690 Жыл бұрын
Hi, while testing class TestMyThing; you only pasing fix fixture to test method, but in the result it is alos printing 'setup and tear down'. How is that happening?
@anthonywritescode Жыл бұрын
pytest hooks up fixtures automatically and it passes them as arguments
@malakarakesh313911 ай бұрын
at 14:33 what's the difference between `return request.param` vs `yield request.param`?
@anthonywritescode11 ай бұрын
in this case nothing. I tend to use yield in case I want to convert it to a context fixture later on
@malakarakesh3139 Жыл бұрын
great videos. could you explain a lit bit more on the "state" with the temp dir as an example?
@JohnZakaria2 жыл бұрын
Test classes vs bare functions, when should I use classes
@IManu96I2 жыл бұрын
I use them when a set of different test share a common set up, variables, fixtures or topic. So that the developer can find them better while providing unique fixtures that only applied to these. This reduces the scope of some fixtures. If some of them are autoused, you can have better control on it for example
@anthonywritescode2 жыл бұрын
(for me): functions: always, classes: never there's just too many ways classes can become unmaintainable (people trying to get too clever with test inheritance, accidentally misnaming a test class is way easier, weird accidentally stateful problems)
@cosmicallyderived Жыл бұрын
Didn’t know about the name kwarg for fixtures.
@petertiggerdine2631 Жыл бұрын
Does the conftest inheritance work in the lasted verisons for pytest?
@swehba2 жыл бұрын
Anthony, love your videos. I always learn something. I've been using pytest for a while, and one thing that has always confounded me is how to add type annotation to a fixture factory function that an IDE like Pycharm can pick up. For example, let's say I have the following (admittedly simplistic fixture) that uses the `faker` package to generate person names with prefixes: @pytest.fixture def create_person_name_with_prefix(faker): def inner(prefix: str = None, last_name: str = None) -> str: prefix = prefix or faker.prefix_nonbinary() last_name = last_name or faker.last_name() return f'{prefix} {last_name}' return inner When I use the fixture factory, I'd like Pycharm to be able to call up the documentation (i.e., signature with types) of the inner function. If this were a standard decorator instead of `@pytest.fixture`, I could use `wraps` from the `functools` module, but that doesn't seem to work here. Is there another way to do something similar to `wraps` with pytest fixture factories?
@anthonywritescode2 жыл бұрын
pycharm I think added special code for pytest fixtures -- so you should be able to use standard type annotations here I think you need a `Protocol` (kzbin.info/www/bejne/h5updJujhq19rs0) to represent this fixture return value due to the optional args: ```python class InnerCallable(Protocol): def __call__(self, prefix: str | None = None, last_name: str | None = None) -> str: ... @pytest.fixture def create_person_name_with_faker(faker) -> InnerCallable: # actual implementation here ... ```
@swehba2 жыл бұрын
@@anthonywritescode Thanks for the lightning fast reply! I did as you suggested, and added type information to the outer/decorator function, and, sure enough, Pycharm sees that and displays it as documentation. However, as expected, it only displays the types, not the formal parameter names as it would with a non-decorated function. Any ideas about how to get the complete documentation (i.e. parameter names and types) to show?
@ChimaChindaDev9 ай бұрын
How do you populate default db during a pytest run.
@GOZES2 жыл бұрын
Something like this for the mock module from the standard library will be super useful :)
@anthonywritescode2 жыл бұрын
yep it's on the list -- hinted at in this video in fact
@iDontFinishAnyt Жыл бұрын
@@anthonywritescode Hopefully its coming soon! Would come super in handy.
@moiattube Жыл бұрын
Nice! Thanks a lot For a moment I thought you had autocompletion on -k option! Wouldn't it be great to have?
@anthonywritescode Жыл бұрын
it's a substring match so idk how it would work
@natiachikovani7660 Жыл бұрын
Thanks a lot for the video. If I am good with Pytest, should I know unittest too? Is it a must or I can be OK with only Pytest?
@anthonywritescode Жыл бұрын
I wouldn't bother with unittest personally
@natiachikovani7660 Жыл бұрын
@@anthonywritescode Neither me! I wanted to hear exactly this ❤️
@duke007x310 ай бұрын
Please explain pytest hooks and plugins)
@empty_pit79202 жыл бұрын
Great video, thanks! I would gladly watch a video about pytest hooks and plugins
@АртемБеляков-к7з Жыл бұрын
Hello Anthony! Could you tell me how to organize work with fixtures that return entities from the database (I load them at each start of the pytest)? The whole difficulty is that these entities depend on each other and are nested in each other. In an advanced project, keeping the database up to date in tests becomes hell. Mocks also don't save much as they also need to be nested inside each other
@cosmicallyderived Жыл бұрын
It sounds like you would create composite fixtures that depend on other fixtures in a representative hierarchy that reflects the domain you’re in.
@АртемБеляков-к7з Жыл бұрын
@@cosmicallyderived Please advise a tutorial on how to do it right
@Quarky_2 жыл бұрын
Fixtures within a scope is pretty cool, didn't know about that :)
@essamgouda16092 жыл бұрын
Your videos are extremely useful !!
@abhinchhabra2502 жыл бұрын
Going over indirect fixtures would be cool 😊
@anthonywritescode2 жыл бұрын
I don't think people should use them
@alice-smith2 жыл бұрын
Love the new font-size :^)
@Keshas1 Жыл бұрын
This is good can write a fixture with a class scope
@thejtoken2 жыл бұрын
Great video, thanks!
@mahanirvaantantra8 ай бұрын
pytest has a lot of abstractions. That's one thing I hate about pytest !
@dankelman95622 жыл бұрын
thank you so much!
@chubbytonio Жыл бұрын
Great video ! thx
@umutgumusluoglu31754 ай бұрын
thats a great video thank you but can you write your codes a little slower i have hard time following your codes as beginner
@anthonywritescode4 ай бұрын
feel free to pause the video at any point! or watch at a slower speed. the speed isn't going to satisfy everyone so the video controls give you the power to get what you want out of it