Unit Testing in Python with pytest | Introduction to mock (Part-9)

  Рет қаралды 76,571

Indian Pythonista

Indian Pythonista

3 жыл бұрын

In this video, learn how to mock object in Python for unit testing with Python.
Code: github.com/nikhilkumarsingh/p...
Playlist: • Unit Testing in Python...
------------------------------------------------------------
Explore my tutorials: nikhilkumarsingh.github.io/tu...
More awesome topics covered here:
WhatsApp Bot using Twilio and Python : tinyurl.com/y9n9ott5
Serverless Rest API using AWS and Python : tinyurl.com/y8yg4vem
Creating Chat Application using Flask, Socket.IO & mongoDB : tinyurl.com/y8kbn4xu
Curses in Python : tinyurl.com/y8ws3x4l
Discovering Hidden APIs : tinyurl.com/y7sdegoq
RegEx in Python : tinyurl.com/y84cnuns
Python for Data Science : tinyurl.com/yd7x6j5e
Introduction to Pandas : tinyurl.com/ycr4qytt
Introduction to Matplotlib : tinyurl.com/y8caem3r
Introduction to Numpy : tinyurl.com/yc8uhtn9
Functional Programming in Python : tinyurl.com/ybubzum6
Python Package Publishing : tinyurl.com/ya2fn3wb
Multithreading in Python : tinyurl.com/ycnummb8
Multiprocessing in Python : tinyurl.com/y8qkjqtx
Parallel Programming in Python : tinyurl.com/yakl5udt
Concurrent Programming in Python : tinyurl.com/y9ppkkhc
Dataclasses in Python : tinyurl.com/y8zfqleq
Exploring KZfaq Data API : tinyurl.com/y7jhs8rm
Just For Fun : tinyurl.com/y9on8gb5
Exploring AWS : tinyurl.com/ydxmhhz9
Jupyter Notebook (Tips, Tricks and Hacks) : tinyurl.com/y8qdhcrp
Decorators in Python : tinyurl.com/y7ghraa9
Inside Python : tinyurl.com/yd8xqbjj
Exploring datetime : tinyurl.com/y96jzylm
Collections in Python : tinyurl.com/ybxltgvk
Networking : tinyurl.com/y97eroql
Computer Vision for noobs : tinyurl.com/y8pxz436
Python for web : tinyurl.com/y829py3g
Awesome Linux Terminal : tinyurl.com/y8no3zso
Intermediate Python : tinyurl.com/yasmecaw
Tips, tricks, hacks and APIs : tinyurl.com/y9xqzzl4
Optical Character Recognition : tinyurl.com/ybt3to6q
Facebook Messenger Bot Tutorial : tinyurl.com/y9wvjc9g
Facebook: / indianpythonista
Github: www.github.com/nikhilkumarsingh
Twitter: / nikhilksingh97
------------------------------------------------------------
#python #pytest #tutorial

Пікірлер: 51
@IndianPythonista
@IndianPythonista 3 жыл бұрын
Code: github.com/nikhilkumarsingh/pytest-tut Playlist: kzfaq.info/sun/PLyb_C2HpOQSBWGekd7PfhHnb9GnqDgrxS
@pratheek5096
@pratheek5096 2 жыл бұрын
BEST BEST BEST EXPLANATION. Finally I understood UT's thank you !!!
@msven
@msven 2 жыл бұрын
This was by far the best video I've seen on pytest and mock. Thank you! Just implemented a ton of these in my tests which cut the code by like 75% and allowed me to do a complete end-to-end test of the platform vs just a few of the functions.
@papunmohanty5968
@papunmohanty5968 3 жыл бұрын
So far I found this tutorial series useful. Instead of magical things, I am learning logical things.
@rsanjay24
@rsanjay24 3 жыл бұрын
Thanks, But the title said pytest, I thought you are going to mock calls with pytest. But this tutorial is using the unit tests to mock, that is not the expectation from the title.
@tarvinder91
@tarvinder91 2 жыл бұрын
Cant thank you enough for this exceptional video. You covered so many scenarios. I was also working on a complex test where I needed to mock some objects which had other functions associated with it that I needed to mock. Using all the learning from your video and after watching is 2 3 times I was able to do that difficult task. I am new to testing too. Great man.
@rutujasurve4172
@rutujasurve4172 7 ай бұрын
This is the best learning video on pytests and mock in the history of python content out there, I am very lucky to have discovered this gem. Please make more such videos, also on AI with Python.
@sfm6295
@sfm6295 11 ай бұрын
Bro, u saved my life thank u!!!!
@SravanKumarduggirala
@SravanKumarduggirala 3 жыл бұрын
Perfectly covered all the topics brother....
@PrantikPanja
@PrantikPanja 11 ай бұрын
Thanks Man ! This is the best explanation of Mock I have found so far. You have reduced my stress a lot.
@propadovicnenad1914
@propadovicnenad1914 2 жыл бұрын
This is an excellent and to the point explanation. Thanks a lot!
@tapojyotipaul9660
@tapojyotipaul9660 2 жыл бұрын
This is video is super helpful! After a lot of exploration about mock and patch, I came across this video and make the job easy for a data science person who is new to unittest! :) :) Thanks a lot!!
@iwswordpress
@iwswordpress 8 ай бұрын
Excellent explanation! One of the best if not the best I have come across. Thanks :)
@joselima7655
@joselima7655 6 ай бұрын
Excellent ! Thank you
@toviazs
@toviazs 10 ай бұрын
Amazing
@ketan_sahu
@ketan_sahu 3 жыл бұрын
Sooper macha 👌🏻👌🏻👌🏻
@vijayannallasami376
@vijayannallasami376 2 жыл бұрын
Excellent video, thank you. bro!
@SagnikDuttaegor92
@SagnikDuttaegor92 3 жыл бұрын
This is very, very good, thank you!
@kirtionthego
@kirtionthego 3 жыл бұрын
Amazing tutorial👨‍🏫📓
@aussabbood3712
@aussabbood3712 2 жыл бұрын
Thank you for these nice tutorials!
@rajeshkab
@rajeshkab 3 жыл бұрын
Excellent
@avinashkaushik2313
@avinashkaushik2313 Жыл бұрын
very well explained sir.. hats off.
@Rudra-go6us
@Rudra-go6us 2 жыл бұрын
clear and concise. super.
@KarthikRao1995
@KarthikRao1995 Жыл бұрын
Good Explanation ! Loved it
@cusatankur296
@cusatankur296 2 жыл бұрын
The explanation is awesome.
@EmadRahman_eee
@EmadRahman_eee Жыл бұрын
Very good explanation. Thank you.
@gyozopajter535
@gyozopajter535 2 жыл бұрын
Great video, thank you so much!
@simplyviki
@simplyviki 3 жыл бұрын
Thanks, I need to create pytest for a python program where I am connecting to postgres db and running select query. How to mock a db connection and how to mock other things like query or tables etc. I am confused about the approach to take to test
@shaz-z506
@shaz-z506 3 жыл бұрын
Hi Nikhil, This playlist is really good, could you please extend this playlist and include how configuring and use tox for automation in testing. Just wanna know if there is any unit testing framework design specific to a machine learning.
@sharangkulkarni1759
@sharangkulkarni1759 Жыл бұрын
gr8 vdeo thanks
@paracha3
@paracha3 2 жыл бұрын
Very well described.
@mojogojoofficial
@mojogojoofficial 3 жыл бұрын
But you are using the unittest library not fully pytest
@silverian
@silverian 2 жыл бұрын
Great material!
@totiqauan9564
@totiqauan9564 2 жыл бұрын
Can't we mock the return_value from get_ip() directly instead of mocking things within the function? For example if I just use the output of get_ip() elsewhere. Is there a difference between the two approaches?
@TJKhara
@TJKhara 3 жыл бұрын
Excellent video. You are a talented teacher. I am glad I found your video. Many thanks for taking the time to create these.
@kunallohar3
@kunallohar3 3 жыл бұрын
What you did at @13.38 to load the code of mock.py
@shubhisrivastava7552
@shubhisrivastava7552 2 жыл бұрын
Great playlist, is there a way to unit test nested functions using pytest?
@rekharekha-nd8ox
@rekharekha-nd8ox 2 жыл бұрын
You are awesome!
@TheSandyfamily1
@TheSandyfamily1 3 жыл бұрын
Can you upload video on how we can mock functions called outside a method.. in lambda
@RJDev-er9bl
@RJDev-er9bl 3 жыл бұрын
@10:21 How are auto importing ? @Indian Pythonista
@janemillervideos
@janemillervideos Жыл бұрын
What if guess_number is inside a class?
@sagarhm2237
@sagarhm2237 Жыл бұрын
bro how to test web loding .
@deeksha6514
@deeksha6514 8 ай бұрын
Why you are teaching this with unittest intead of pytest?
@TJKhara
@TJKhara 3 жыл бұрын
@5:38 how did you look into the mock object?
@IndianPythonista
@IndianPythonista 3 жыл бұрын
`Shift + Tab` on jupyter notebook.
@adityarajora7219
@adityarajora7219 3 жыл бұрын
I think the concept of mocking is absurd, We didn't test our code actually, LOL.
@stanislavkryshchuk9200
@stanislavkryshchuk9200 3 жыл бұрын
✌️🇺🇦
@mahdihosseinali7492
@mahdihosseinali7492 2 жыл бұрын
using unittest.mock is not the best way to mock. It's like using requests and pycurl here and there. pytest uses monkeypatch for mocking
@TonyBoy24999
@TonyBoy24999 2 жыл бұрын
Great video, question, how would you mock roll_dice itself if guess_number was not calling it? Below doesn't work @mock.patch("tut9.myapp.dice.roll_dice") def test_guess_number2(mock_roll_dice): mock_roll_dice.return_value = 3 assert roll_dice() == 3
@TonyBoy24999
@TonyBoy24999 2 жыл бұрын
answered my own question, you will need to import the whole module, see example below for anyone with same issue: import tut9.myapp.dice @mock.patch("tut9.myapp.dice.roll_dice") def test_guess_number2(mock_roll_dice): mock_roll_dice.return_value = 3 assert tut9.myapp.dice.roll_dice() == 3 Not sure why the other way doesn't work though
Unit Testing in Python with pytest | Advanced Mocking (Part-10)
17:17
Indian Pythonista
Рет қаралды 28 М.
How To Write Unit Tests in Python • Pytest Tutorial
35:34
pixegami
Рет қаралды 134 М.
Who has won ?? 😀 #shortvideo #lizzyisaeva
00:24
Lizzy Isaeva
Рет қаралды 64 МЛН
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 42 МЛН
Now THIS is entertainment! 🤣
00:59
America's Got Talent
Рет қаралды 37 МЛН
39kgのガリガリが踊る絵文字ダンス/39kg boney emoji dance#dance #ダンス #にんげんっていいな
00:16
💀Skeleton Ninja🥷【にんげんっていいなチャンネル】
Рет қаралды 7 МЛН
Intro to Python Mocks | Python tutorial
18:42
Red Eyed Coder Club
Рет қаралды 80 М.
Python Tutorial: Unit Testing Your Code with the unittest Module
39:13
Corey Schafer
Рет қаралды 1,3 МЛН
Professional Python Testing with Mocks
21:19
NeuralNine
Рет қаралды 46 М.
Unit testing Python code using Pytest + GitHub Actions
23:02
How To Write Unit Tests For Existing Python Code // Part 1 of 2
25:07
PyTest • REST API Integration Testing with Python
37:24
pixegami
Рет қаралды 78 М.
Who has won ?? 😀 #shortvideo #lizzyisaeva
00:24
Lizzy Isaeva
Рет қаралды 64 МЛН