Тёмный

How To Write Unit Tests in Python • Pytest Tutorial 

pixegami
Подписаться 35 тыс.
Просмотров 130 тыс.
50% 1

Learn how to test your Python code by writing unit tests with the Pytest framework.
In this video I'll be covering how to write and run unit tests, how to check if an Error is raised, how to use test fixtures, and how to mock dependencies.
💻 Code: github.com/pixegami/simple-py...
👉 Pytest Documentation: docs.pytest.org/
👉 Unittest Mock: docs.python.org/3/library/uni...
📚 Chapters
00:00 Introduction
02:45 Install Pytest and setup the project
04:14 Running your first unit test
06:50 Implement your test (with "assert")
11:24 How to test that an Error is raised
18:30 How to run a specific unit test file/method
19:50 How to see print statements in pytest
20:27 Implementing "get_total_price" test
23:10 Using pytest fixtures to set up context for your tests
27:00 When your tests depends on another module
30:50 How to mock dependencies (using unittest Mock)
34:30 Wrap-up
#pytest #python

Опубликовано:

 

24 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 216   
@soumyazyx
@soumyazyx 2 года назад
I just loved the way the entire tutorial was planned and executed. The build up was so apt. Loved every bit of it. Thanks for your time and effort. First time here - subscribed
@pixegami
@pixegami 2 года назад
Thanks! I did put a lot of thought into planning it, so that it covers all the topics with little wasted effort. I really want to respect my viewer's time - so I really appreciate your comment :)
@tpag20
@tpag20 2 года назад
I agree!! this video is best pytest tutorial
@picassoofai4061
@picassoofai4061 Год назад
Agree 💯
@abhishekanand2782
@abhishekanand2782 3 месяца назад
This will rank in top 3 videos of all time in Python Unit Testing on RU-vid. Had it been a category called 'Python Unit Test' in Academy Awards. It sure will win the Oscar.
@pixegami
@pixegami 2 месяца назад
Thank you! Glad you enjoyed it :)
@siewierap
@siewierap Год назад
One of the best videos about testing I've ever watched, that's excellent, straight to the point
@pixegami
@pixegami Год назад
Thanks! That's my goal with these videos :)
@hadisrour5339
@hadisrour5339 2 года назад
Most underrated channel on RU-vid 🙏🏽
@pixegami
@pixegami 2 года назад
Thanks! I appreciate that.
@bryannahrwold5462
@bryannahrwold5462 Год назад
Loved your straight-forward approach and building of functionality as you go. Excellent work. Thanks!
@pixegami
@pixegami Год назад
Thanks! I hope it helped!
@bryannahrwold5462
@bryannahrwold5462 Год назад
@@pixegami There is only one thing missing from this video and pretty much everywhere I've looked on the Internet: How to import a function in a directory from a file in another directory at the same depth. This is import for testing packages with the directory structure /src/file with /test/test_file or when one package is accessing another one. A video on that would be terrific!
@barnabykent6698
@barnabykent6698 Год назад
Very practical and accessible tutorial. I enjoy your concise and clear style. This is content with high sound to noise ratio. Subscribed!
@pixegami
@pixegami Год назад
Thanks! I know everyone is busy and want to learn as quickly as possible, so I aim to keep the content lean. Good to know that the effort is not wasted :)
@horoshuhin
@horoshuhin Год назад
really piqued my interest towards the end. great explanation. would love to see part 2 with more advanced test case scenarios. thanks
@Shawncres2049
@Shawncres2049 Год назад
Solid tutorial, great explanation. I like the way it was the closest to hands on learning without having to actually be hands on.
@pixegami
@pixegami Год назад
Awesome, thank you!
@Holasticlogger
@Holasticlogger 10 месяцев назад
In Such a short time you have covered so many features of Pytest...That's Amazing !!!! Loved the video and explanation! Pytest is indeed a powerful test framework !!
@pixegami
@pixegami 9 месяцев назад
Glad you liked it :)
@janaeshkrish
@janaeshkrish 2 года назад
It was a great video it helped me a lot to get started with PYTEST, assert ,fixtures and mock. I just loved it
@r7-wq8ly
@r7-wq8ly Год назад
Thank you so much!! I used to think testing was hard and I was afraid to learn, but now I've changed that! Great video🤩
@pixegami
@pixegami Год назад
Testing seems hard because I think there's not enough education about it! But I'm glad this video helped!
@ddawgncc2
@ddawgncc2 Год назад
EXCELLENT Tutorial. Love your approach and style to teaching. Very clear, concise and to the point! Thank you for posting!👍
@pixegami
@pixegami 10 месяцев назад
Glad you enjoyed it!
@abelashenafi6291
@abelashenafi6291 10 месяцев назад
Thanks my friend. I can't thank you enough for the knowledge you just shared in just 35 minutes. I had absolutely 0 experience with Unit tests in general but now I really do. I really loved the way you started small and got a bit deeper. This is what most people just don't do. You probably know about Gall's law "All complex systems work, are built on top of simpler systems that worked" Hence, if you want to build a complex system, first build a simple system that works and build on top of that. Thank you. I really mean it. You just got a new subscriber. Abel
@pixegami
@pixegami 9 месяцев назад
Thank you for the thoughtful comment :) Glad you found the content useful. Stay tuned, I hope to provide more useful content right here on this channel.
@terryphelps4204
@terryphelps4204 9 месяцев назад
Nicely done. No bullshit background music, and silly-ass fancy graphics and sound effects. Just good technical knowledge, explained well.
@BruceElgort
@BruceElgort 2 года назад
This is one of the best videos on pytest I have seen. Thank you for it.
@pixegami
@pixegami 2 года назад
Thank you, I appreciate your comment!
@sleekunique6060
@sleekunique6060 Год назад
Great video. Please make more. You explain things without overcomplicating the process.
@pixegami
@pixegami Год назад
Thanks! More to come. Feel free to suggest topics you'd like to see.
@ChaosArtist
@ChaosArtist 2 года назад
Thanks for this tutorial, I'm new to Pytest and this was very helpful.
@stankatsion6286
@stankatsion6286 21 день назад
This is by far one of the best tutorial lessons! It's like every time I'm thinking 'but why that' you continue with explaining exactly what I wanted to know!
@pixegami
@pixegami 19 дней назад
Really glad to hear that! Thank you :)
@dr.schlopp4089
@dr.schlopp4089 Год назад
Excellent video! You have a clear talent for teaching and being able to express your ideas thoughtfully and in a manner that is easy to understand. I'm excited to be able to subscribe to a new channel that will soon blow up in popularity once more people see the quality of your content! I'll be able to say, _"I was there..."_ 😂 Subbed!
@pixegami
@pixegami Год назад
Thanks! I appreciate the support :)
@rosscoguitar
@rosscoguitar 2 года назад
Thank you for this video. You've done a really great job of explaining these concepts.
@pixegami
@pixegami 2 года назад
Thanks! I appreciate the comment :)
@TheSaadcheema
@TheSaadcheema 2 года назад
Best tutorial so far on pytest!
@pixegami
@pixegami 2 года назад
Thanks! Hope it was useful.
@WistfulOcean
@WistfulOcean Год назад
Very accessible and clear, thank you for that!
@pixegami
@pixegami 10 месяцев назад
Glad it was helpful!
@sahngcobo
@sahngcobo Год назад
Very clear and well spoken instructions
@machinimaaquinix3178
@machinimaaquinix3178 5 месяцев назад
Hey this was an EXCELLENT and concise intro to pytest! The explanations and examples were so clear, and went beyond the usual test video toy "x + y" drivel . I will strive to use the testing workflow model you demonstrated. The almighty YT algo popped this video in after a recent freecodeacademy Pytest intro video - and honestly, this beats that one by far! And it is three times as long! In fact, I'm linking this video in that video's comments! You rock! And you got a new sub!
@pixegami
@pixegami 5 месяцев назад
Thank you for your kind comments :) I try hard to structure the content to be as direct and useful as possible, so I appreciate hearing whenever it helps someone out.
@guipe7712
@guipe7712 2 года назад
Great Video. I finally understood most about the pytest framework. Thamks friend
@juliocardenas4485
@juliocardenas4485 Год назад
Thank you for sharing your talents. It’s well organized, clear, and useful.🙏🏾👨🏽‍💻
@pixegami
@pixegami Год назад
Thank you! Glad you found it clear!
@renitur2292
@renitur2292 Год назад
Excelent video. You are a natural speaker. Thx!
@pixegami
@pixegami Год назад
Thank you!
@mikiyasgetachew77
@mikiyasgetachew77 Год назад
very cool Tutorial for pytest. Especially for beginners. Everything is crystal and clear.
@pixegami
@pixegami Год назад
Thank you! Glad it was helpful!
@adhavarrv
@adhavarrv Год назад
Thanks for a great and simple tutorial on PyTest!
@pixegami
@pixegami Год назад
Glad it was helpful!
@filmedbyjulia124
@filmedbyjulia124 Год назад
helpful video on unit testing! Thank you!
@ChanceMinus
@ChanceMinus Год назад
Excellent! Thank you.
@947ihi
@947ihi Год назад
I can't thank you enough for this video🙌 This helped me so much!
@pixegami
@pixegami Год назад
Glad it helped!
@theoryofeverywhere6293
@theoryofeverywhere6293 6 месяцев назад
Extremely well done and clear. Thanks so much for this!
@pixegami
@pixegami 6 месяцев назад
You're very welcome!
@chaimapro9085
@chaimapro9085 11 месяцев назад
Insightful, thank you!
@DaCosmoz
@DaCosmoz Год назад
This was a very helpful and clear tutorial, thank you very much!
@pixegami
@pixegami Год назад
Glad to hear it!
@rasheedibraheem6839
@rasheedibraheem6839 Год назад
What a great tutorial! Thank you!
@pixegami
@pixegami Год назад
Glad it was helpful!
@Themuralisp
@Themuralisp Год назад
very nicely explained. Thank you
@ChongSun
@ChongSun Год назад
Thanks! Nice TDD tutorial.
@pixegami
@pixegami Год назад
Glad you liked it!
@davidbalague9311
@davidbalague9311 Год назад
Excellent and comprehensive tutorial, very well explained and accessible. Best ever! Good Job!!
@mohammedshoab2778
@mohammedshoab2778 4 месяца назад
Perfectly explained an important topic!
@pixegami
@pixegami 4 месяца назад
Glad you liked it!
@timo_b3
@timo_b3 9 месяцев назад
Wow, you covered everything that confused me as a beginner! Thank you
@pixegami
@pixegami 9 месяцев назад
Glad it was helpful!
@nawazhussain1281
@nawazhussain1281 3 месяца назад
I got this video from google and assumed it was a popular channel. How is it only at 22k. Very well explained vs coming to the video with a bunch of testcases written
@xiliu1842
@xiliu1842 Год назад
Very Nice video, Thanks man!
@pixegami
@pixegami Год назад
Glad you liked it!
@shelleycurrie764
@shelleycurrie764 Год назад
Great, thanks you covered enough for me to get going.
@pixegami
@pixegami Год назад
You're welcome! Good luck.
@ukplaymaker15
@ukplaymaker15 Год назад
Thank you for this amazing tutorial.
@pixegami
@pixegami Год назад
I hope it was helpful!
@furolio
@furolio Год назад
This channel deserves more subscribers
@pixegami
@pixegami Год назад
Thanks! I'm glad you think so :)
@gasparottogui
@gasparottogui 8 месяцев назад
Great tutorial! Simple and effective. Thanks!
@pixegami
@pixegami 7 месяцев назад
Glad it was helpful!
@dhartdata5998
@dhartdata5998 Год назад
very informative. Thanks
@mryderoc
@mryderoc 11 месяцев назад
Nice job! Great starter for pytest. Thanks
@pixegami
@pixegami 10 месяцев назад
Glad you like it!
@marcinbiedron3241
@marcinbiedron3241 Год назад
You are a good teacher, thank you
@pixegami
@pixegami Год назад
Thank you! 😃
@ziad9533
@ziad9533 Год назад
A very useful video, thank you!
@pixegami
@pixegami Год назад
Glad it was helpful!
@CrashLaker
@CrashLaker Год назад
awesome! had everything for me to get started. side_effects ftw!
@pixegami
@pixegami Год назад
You're welcome!
@cOnT3ST
@cOnT3ST 10 месяцев назад
Huge thanks for the vid.
@pixegami
@pixegami 10 месяцев назад
Glad it helped
@fabiohenriqueteixeira5566
@fabiohenriqueteixeira5566 3 месяца назад
Excellent content!!!
@mohammederifaimaamir7087
@mohammederifaimaamir7087 Год назад
Thank you so much, u've made my life easier
@pixegami
@pixegami Год назад
Awesome! Glad to hear that!
@magorzatastolarska4274
@magorzatastolarska4274 Год назад
Great tutorial! Thanks a lot.
@pixegami
@pixegami Год назад
You're welcome!
@sebastiancontreras3300
@sebastiancontreras3300 Год назад
Thank you! U totally domain the subject entirely
@pixegami
@pixegami Год назад
Glad it was helpful!
@python360
@python360 2 года назад
Really useful, thank you!
@pixegami
@pixegami 2 года назад
Glad it was helpful!
@amitsharma5551
@amitsharma5551 8 месяцев назад
Awesome Video...never seen such a nice explaination of things..love it!!
@pixegami
@pixegami 7 месяцев назад
Glad you liked it!
@shmuelk3018
@shmuelk3018 Год назад
Amazing, I really enjoyed it
@pixegami
@pixegami Год назад
Awesome, thank you!
@aravinddt16
@aravinddt16 4 месяца назад
Well structured!
@pixegami
@pixegami 4 месяца назад
Thank you!
@sunnyding602
@sunnyding602 Год назад
super helpful. Thank you! youtube should rank your video to the 1st position
@pixegami
@pixegami Год назад
Thanks!
@danielrossano3322
@danielrossano3322 2 года назад
keep up the good work!
@pixegami
@pixegami 2 года назад
Thanks for the encouragement!
@vijaybabaria3253
@vijaybabaria3253 2 года назад
Would love to see more videos on testing, and integration test to verify end to end testing, thanks 🙏🏼
@pixegami
@pixegami 2 года назад
That's a great idea - thanks for the feedback :) I can definitely cover more testing topics.
@betagroobox
@betagroobox Год назад
Yes, please!🙏
@winnumber101
@winnumber101 Год назад
very high quality video
@pixegami
@pixegami Год назад
Thanks. I appreciate it!
@fatihnri2484
@fatihnri2484 Год назад
I rarely comments but this is a great video on PyTest!
@user-gd4uf9mg9m
@user-gd4uf9mg9m 9 месяцев назад
I hope you take this as a compliment. You are filling in the gap left by Corey Schafer!
@pixegami
@pixegami 9 месяцев назад
Thank you! Corey Schafer is a legend and I'm humbled to be compared to them.
@MrAndyG67
@MrAndyG67 5 месяцев назад
Very useful intro, thanks.
@pixegami
@pixegami 5 месяцев назад
Glad it was helpful!
@rohithdiya
@rohithdiya Год назад
Thanks very useful :)
@pixegami
@pixegami Год назад
Glad it was helpful!
@user-ln6hz2nb7o
@user-ln6hz2nb7o 5 месяцев назад
Thanks for your time and effort awesome video!!!!
@pixegami
@pixegami 4 месяца назад
Thank you, I appreciate your comment!
@mathewsjoy8464
@mathewsjoy8464 2 года назад
Perfect!
@pixegami
@pixegami 2 года назад
I hope it's useful!
@pietheijn-vo1gt
@pietheijn-vo1gt Год назад
Great video. Could you make a part 2 of this? For example: how to work with context across multiple tests, how to work with scopes, how to work with test data for AI, different types of exceptions etc.
@pixegami
@pixegami Год назад
Interesting - I hadn't considered a part 2, but I'm keen to hear your use cases for the things you mentioned (particularly about AI testing - do you have a use case in mind for that)?
@pietheijn-vo1gt
@pietheijn-vo1gt Год назад
@@pixegami I worked on a personal project where a pokerbot would receive real images of pokercards and then used a simple CNN to decide which card it was. In order to test the flow I had to import the model, retrieve some test images etc. But I also just wondering in general how to combine unit testing and data science. I really enjoy developing well tested code and these jupyter notebooks are a nightmare to work with when I do anything AI related
@raphaelhunold6812
@raphaelhunold6812 Год назад
good video. You earn a new follower
@pixegami
@pixegami Год назад
Thanks and welcome!
@BollyGasm
@BollyGasm 8 месяцев назад
wow, helped me a lot
@pixegami
@pixegami 7 месяцев назад
Glad it helped :)
@ajinkyathorawat9814
@ajinkyathorawat9814 Год назад
nice information.
@pixegami
@pixegami Год назад
Thanks for the feedback. I've reduced the ad settings so now it should be a smoother viewing experience.
@chriskeo392
@chriskeo392 Год назад
You're a great teacher. Wonder if you have a tutorial on app structure too?
@pixegami
@pixegami Год назад
Not yet, but I'll note it down as an idea that my audience wants! Thank you.
@user-ht6vy4gh7h
@user-ht6vy4gh7h 11 месяцев назад
Excellent video! it's quite clear and concise. By the way, I am curious what VSCode colorscheme you are using in the video?
@pixegami
@pixegami 10 месяцев назад
Thank you! I use monokai.pro/ - I've tried a lot of different themes, but I always come back to this one.
@jinettew.3192
@jinettew.3192 Год назад
Really nice intro.
@pixegami
@pixegami Год назад
Thanks!
@gregwoolley
@gregwoolley Год назад
Excellent tutorial, very helpful! Just one request, is there a way you could position your mic so your keyboard is not so loud (particularly the Return-Key)? Maybe use a 'unidirectional' mic and some type of dampener under your keyboard?
@pixegami
@pixegami Год назад
Thanks for the feedback! Glad you enjoyed the video. And yes, I agree the keyboard is too loud. Sorry! I've actually upgraded my Mic to a vocal mic, and I'm using a different (softer) keyboard now in my newer videos so I hope it'll feel/sound better for you.
@python360
@python360 2 года назад
20:07 You can also use "pytest -k test_can_get_total_price"
@pixegami
@pixegami 2 года назад
Ah, thanks for calling out!
@priteshkhilari1918
@priteshkhilari1918 3 месяца назад
Thanks alot
@krishanunayek785
@krishanunayek785 Год назад
Hello, This is really very good content. It helped me a lot to implement unit test cases. I am trying to implement some retry mechanism (using HTTPadapter , retry package) when the given http errors (500,502,503,504) occur. Now I am not able to implement the retry mechanism as well as the unit testcases for the same. It would be really helpful if you create some video on the same topic.
@hardcorewithin
@hardcorewithin 3 месяца назад
great video! what are you using as a terminal ? I love the way it displays the cwd as shadow instead of showing the full path , can you please share the theme name ? thanks !
@stannylou1636
@stannylou1636 Год назад
May I ask what operating system you're using? Great tutorial by the way.
@pixegami
@pixegami Год назад
Thank you! In this video I'm using Ubuntu Linux. It's probably my favourite programming environment, although these days I'm using a Mac because I find I also need a lot of creative software (to make the actual videos).
@Hinkakan
@Hinkakan Год назад
Great explanation and flow in the video: I find myself sitting with two questions at the end though: 1. Your implementation of the fixture returned one instanciated class. What about if I want to return several values, e.g. environment values, connenction details to databases. How would I return that? Would I return a list of values? Or can I somehow bake it into the function arguments, what information I want to retrieve? 2. I find myself confused on the last part with the Mock module. The way I see it: 1. You instanciate an empty class 2. You call an empty method of this class (none of these fail because both are in fact defined, just have no content) 3. You call Mock to get a value, and you pass in the function to handle the logic. However, the mock_get_item requires an item argument passed to it, yet I do not see you pass anything. Should mock_get_item not receive a list os something that contains the items added to the cart? And in the assertion, you pass in item_database, but the way I read the code, the item_database should still be an empty class since the .get method does nothing yet..
@pixegami
@pixegami Год назад
Great questions! 1. How do I return a list of values or (anything else) from a fixture? Well, a fixture can return any type of value. So you could have a fixture that returns a tuple. Or you might choose to have a Class or a module that groups together a bunch of different values you want to use together. You are also not limited to using one fixture per test. If you made another fixture called "cart2", then you should be able to use both fixtures in the test by writing: `def test_can_get_total_price(cart, cart2)`. Take a look here for more examples: docs.pytest.org/en/6.2.x/fixture.html 2. You don't see anything being passed in to `mock_get_item` because we never use it directly in the test. We *assign* it to our item_database's "get()" function: "item_database.get = Mock(side_effect=mock_get_item)". Then we call `cart.get_total_price(...)`, which then goes on to call the item_database.get() with our arguments: "total_price += price_map.get(item)": github.com/pixegami/simple-pytest-tutorial/blob/aa65d4b457039dddaeb0a75a359f223a25ec3d09/shopping_cart.py#L23 So when you say " item_database should still be an empty class since the .get method does nothing" - it's actually not true because we *mocked* the get() method to do something for us with this line. We basically 'replaced' the functionality of `item_database.get()`: github.com/pixegami/simple-pytest-tutorial/blob/aa65d4b457039dddaeb0a75a359f223a25ec3d09/test_shopping_cart.py#L42 Hope this helps!
@olaniyanayodele5986
@olaniyanayodele5986 Год назад
Great video. Just learnt pytest. Mind sharing your vs code theme setup?
@pixegami
@pixegami Год назад
Thanks! For VSCode I use the paid "Monokai Pro" theme, but they do have a free trail. Other themes I've enjoyed in the past are "Nord" and "Ayu".
@harryz3314
@harryz3314 Год назад
What is your keyboard? It sounds great!
@pixegami
@pixegami Год назад
In this video I just used a DURAGOD keyboard with blue-key switches. I've since changed now to a Moonlander keyboard with brown switches. They keyboards don't really make too much difference to me as long as they are the thicker mechanical types.
@hj-wl4vk
@hj-wl4vk Год назад
What's your vscode theme? It 's great!
@jtech8959
@jtech8959 Год назад
Hi, great video thanks! Could you explain why you didnt or when to use mock.patch instead of what you did here creating an instance of the db and return a mock.
@pixegami
@pixegami Год назад
Great suggestion! `mock.patch` works too, and is probably a good way to do it. I didn't choose to use it here mainly because I wanted to make the relationship between the mock and the dependency clearer. Introducing mock.patch would introduce some new mental concepts (with it being a decorator), and I didn't want that at this stage in the tutorial. Now, in actual real projects I've used mock.patch before, but it started to become annoying when there's maybe 5-6 things I needed to patch for one test. A lot of nesting, ordinal arguments, and a lot of repetition across various test cases. I am now learning towards fixtures instead, to set up more complex mock behavior.
@shreshtapagidimarry9603
@shreshtapagidimarry9603 11 месяцев назад
Which ZSH theme is that ? I would like to install the same. Looks amazing,
@pixegami
@pixegami 10 месяцев назад
I have a video and a GitHub repo covering the Ubuntu ZSH theme I use: github.com/pixegami/terminal-profile
@Confusedcapybara8772
@Confusedcapybara8772 Год назад
That keyboard sounds good 👌 specs?
@pixegami
@pixegami Год назад
Haha I've used a lot of keyboards so I'm not sure which one specifically I used in this video. I think it was probably this one, with the blue Cherry switches: amzn.asia/d/3uXqhmU
@nakawesijuliet2363
@nakawesijuliet2363 8 месяцев назад
Very helpful to a beginner like me,thanks. can you help me on how to integrate zoom in a django project?
@pixegami
@pixegami 7 месяцев назад
Sorry I haven't done any Django projects yet but it's on my list!
@nakawesijuliet2363
@nakawesijuliet2363 7 месяцев назад
Cool@@pixegami
@vietnamdang1917
@vietnamdang1917 10 месяцев назад
Hi Pixegami, Python is totally new to me. I am very interested in learning it. Would you mind sending me a link to or show me how to download/install Python to my laptop? Thanks in advance.
@pixegami
@pixegami 9 месяцев назад
Python is a great programming language to learn! I have a complete playlist on a learning roadmap and how to install it and learn all the basics here: ru-vid.com/group/PLZJBfja3V3Rsbiz84Z63IXnTQZH_Rnfuo&si=-hMurnRNSf2s7J_m
@chriskeo392
@chriskeo392 10 месяцев назад
Wish he did a more advanced pytest course
@prasenjitgiri919
@prasenjitgiri919 6 месяцев назад
Great tutorial, but I still dont seem to get how the item database is getting populated. we never passed the cart values to it, so how did it even know ?
@pixegami
@pixegami 6 месяцев назад
Yup! In unit tests, we don't want to use real databases or values, so we "mocK' them. We're saying "pretend I have a database, and when I query for 'x', give me '5'." This way we can just test that specific unit of the code (usually just a class or a function) without having to worry about the other parts of app.
@danielwilkowski5899
@danielwilkowski5899 Год назад
17:19 what you should actually do, is write another test that checks if you can add 5 items and nothing happens. These two tests would be sufficient.
@darcash1738
@darcash1738 5 месяцев назад
what are flat directories? how can i make it so i can just directly reference the file like that
@pixegami
@pixegami 4 месяца назад
Here's a section in the doc on how to specify which tests to run: docs.pytest.org/en/latest/how-to/usage.html#specifying-which-tests-to-run E.g. for a specific function you can run `pytest tests/test_mod.py::test_func`.
@dbzkidkev2
@dbzkidkev2 Год назад
Great video but question, why didnt you use monkeypatch?
@pixegami
@pixegami Год назад
Good call. I wanted to start off with more primitive tools, and more generalisable knowledge. Mocking and stubbing is pretty widely used, but I think patching is more prominent in Python testing. I'm also not a fan of positional arguments for the mocked items, I think fixtures afford more precision and flexibility.
@darcash1738
@darcash1738 5 месяцев назад
set up a run configuration for pytest but it gave DeprecationWarning: pkg_resources is deprecated as an API. How to fix?
@pixegami
@pixegami 4 месяца назад
Hmm, not sure where that is coming from. I'd probably recommend just tracing back the error to find where it's coming from, and also just updating all the dependencies so they are all on the latest version. But if it's just a warning, I don't think it should impact you.
@AndresRodriguez-vv3fs
@AndresRodriguez-vv3fs 2 года назад
Hey! Loved the video, but could you keep speaking when you code? Helps a lot when coding along! Much love
@pixegami
@pixegami 2 года назад
Thanks for the feedback! I'll definitely try to keep talking more - I need a lot of practice talking and coding at the same time 😅
Далее
PyTest • REST API Integration Testing with Python
37:24
Pytest Tutorial - How to Test Python Code
1:28:39
Просмотров 161 тыс.
При каком ВЕСЕ ЛОПНЕТ ШИНА?
18:44
Python RAG Tutorial (with Local LLMs): AI For Your PDFs
21:33
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
Intro to Python Mocks | Python tutorial
18:42
Просмотров 79 тыс.