I’ve been avoiding unit tests for a while, but some of my users are commenting that there are small bugs that are detracting from the tools. This video is tremendously helpful in providing an overview and kickstart to using pytest. Excellent presentation and thank you!!
Thanks for the video, good to see a tutorial from a TDD advocate. I agree that Given, When, Then is a good structure to use for the actual code of a test, e.g. GIVEN: instantiate the class / setup functionality WHEN: call the function being tested THEN: assert but I question writing an actual comment of it above the test. If requirements change and therefore this test needs to change, there's a risk that this comment will become a lie if the programmer forgets to update it, however the code will always tell the truth
So, as the explanation in video wasnt enough for me to understand the yield test_client vs return test_client, could you please provide me some additional explanation of why should we do it like this? Thanks in advance, this is the last puzzle I need to completly understand the concepts of pytest.
Well the difference between them is actually pretty simple. When you "return" a value, the function that returned the value ends, and no other code in it will be executed. But when you call "yield" you return the value to the function above (just like with "return"), but the code still continues. This is important if you need some sort of a teardown or cleanup. The best example of using "yield" would be with file handling. Imagine that you have a function that opens a certain file and then returns it. But there is a problem, you also have to close the file after you return it. So, you change the "return" statement to "yield" and then call the .close() function below it. Hope that helps!
I’ve been avoiding unit tests for a while, but some of my users are commenting that there are small bugs that are detracting from the tools. This video is tremendously helpful in providing an overview and kickstart to using pytest. Excellent presentation and thank you!!
That was a very calming and soothing and relaxing explanation that really consolidates in my mind. Thank you
Thanks for the video, good to see a tutorial from a TDD advocate. I agree that Given, When, Then is a good structure to use for the actual code of a test, e.g.
GIVEN: instantiate the class / setup functionality
WHEN: call the function being tested
THEN: assert
but I question writing an actual comment of it above the test. If requirements change and therefore this test needs to change, there's a risk that this comment will become a lie if the programmer forgets to update it, however the code will always tell the truth
Thank you so much, Patrick! I have been struggling with TDD for awhile now. Alot of the concepts really clicked watching this.
Great video!
This is a great presentation. Thanks you so much. You made me more understand about TDD.
So, as the explanation in video wasnt enough for me to understand the yield test_client vs return test_client, could you please provide me some additional explanation of why should we do it like this? Thanks in advance, this is the last puzzle I need to completly understand the concepts of pytest.
Well the difference between them is actually pretty simple. When you "return" a value, the function that returned the value ends, and no other code in it will be executed. But when you call "yield" you return the value to the function above (just like with "return"), but the code still continues. This is important if you need some sort of a teardown or cleanup. The best example of using "yield" would be with file handling. Imagine that you have a function that opens a certain file and then returns it. But there is a problem, you also have to close the file after you return it. So, you change the "return" statement to "yield" and then call the .close() function below it. Hope that helps!
@@vladislavkorecky Amazing answer Vladislav, highly appreciate that! :)
Incredibly helpful presentation! Thank you!
Informative and great delivery. Thank you.
Thank you, helped a lot!
This is amazing!
unit test did not work 'TypeError: __init__() takes 1 positional argument but 2 were given' :-(