Lisa Roach - Demystifying the Patch Function - PyCon 2018

  Рет қаралды 46,820

PyCon 2018

PyCon 2018

Күн бұрын

Пікірлер: 54
@mohammadsamir2713
@mohammadsamir2713 4 жыл бұрын
What's going on, her ability to explain things blew my mind !!
@rmarianoanaya
@rmarianoanaya 6 жыл бұрын
Amazing talk! Really good explained, entertaining, and useful. "Mock where the object is used", is a very good practical advice! Kudos to the speaker, really superb!
@lightninginmyhands4878
@lightninginmyhands4878 5 жыл бұрын
11:12 - Scope tier -- Context Manager - duration is a partial life of a function -- Function decorator - duration is the entire life of a function -- Class decorator - duration is the entire life of all functions inside the class
@Melindax3Cardenas
@Melindax3Cardenas 2 жыл бұрын
this is the clearest explanation of patching I've found online
@MichaelFoord
@MichaelFoord 6 жыл бұрын
The best talk of PyCon 2018!
@don0071
@don0071 6 жыл бұрын
Great talk Lisa! You have addressed the most common problem that the patchers usually confused with
@findingMyself.25yearsago
@findingMyself.25yearsago 4 жыл бұрын
A very wonderful clear talk of Lisa 🤩🤩... Haha didn't expect the author would be in the tall😂
@lightninginmyhands4878
@lightninginmyhands4878 5 жыл бұрын
13:05 - It's recommended to use Context Manager for built-in functions 14:00 - Remember that a decorator creates a MagickMock object. It must be passed as an argument into the tested function. 14:39 - Yes, decorators can be stacked. However this is at the expense of DRY. 14:53 - in `setUp`, your patches can be started. You can then stop them all in `addCleanup` if a test goes bad before `tearDown` happens.
@xiuwensun9944
@xiuwensun9944 5 жыл бұрын
Very good video and worth the time watching. Much clearer than Python documentation.
@clee546
@clee546 2 жыл бұрын
Thank you! Lisa. Your presentation is succinct, clear and engaging; illustrations and examples are simple and to the point. I was new to patch and this really help me out a lot.
@saifmohammed1481
@saifmohammed1481 2 жыл бұрын
Amazing explanation, especially showing what really happens under the hood... Been struggling with finding good documentation on mocking from the past few days and dunno how i missed this
@lightninginmyhands4878
@lightninginmyhands4878 5 жыл бұрын
6:50 - Target must be importable -- patch auto-imports the target for you 7:30 - Don't patch where the function is declared, but where it is referenced 8:42 - If you import a function from a module: Use the importing module's name to target the function instead of the imported module. This is because the importing module's lookup table contains the function 9:36 - If you import an entire module: Use the imported module's name to target the function instead of the importing function.
@croonix
@croonix 4 жыл бұрын
Many thanks to Lisa Roach! Very very informative and useful!
@prowez
@prowez 3 жыл бұрын
Great presentation! Patched a lot of holes in my understanding.
@liamsism
@liamsism 5 жыл бұрын
Nice talk! There is some an incorrect example at 22:35. It should be self.x = 20 otherwise it's understandable why f.x is not working.
@adamhendry945
@adamhendry945 2 жыл бұрын
I was just gonna say that.
@japrogramer
@japrogramer 5 жыл бұрын
God that glove cursor made me anxious
@kessakessa9394
@kessakessa9394 3 жыл бұрын
Perfect explanation. Even layman can understand...
@xmuta
@xmuta Жыл бұрын
Very good and useful presentation.
@Radioguy00
@Radioguy00 4 жыл бұрын
Extremely clear and concise presentation. Thanks
@2LazySnake
@2LazySnake 2 жыл бұрын
Amazing talk, thank you very much for sharing!
@12804olivier
@12804olivier 6 жыл бұрын
haha thank you. You saved me so much time at work.
@nch77884
@nch77884 4 жыл бұрын
Great explanation for mock n patch. Thanks Lisa!
@PradeepSusarla
@PradeepSusarla 6 жыл бұрын
github link or speakerdeck pycon18 does not show any files for this presentation. can anyone please share the link?
@jasonhoman6525
@jasonhoman6525 2 жыл бұрын
Use property in patch,“new” to mock a case statement flow controlled by a string input? Do they have that in python. Thinking in JavaScript
@prasukjain9982
@prasukjain9982 5 жыл бұрын
Really nice explained. It's gonna be very helpful to me.
@ActuallyFiona
@ActuallyFiona 2 жыл бұрын
This was a huge help. Thank you!
@jasonhoman6525
@jasonhoman6525 2 жыл бұрын
This is amazing! Thank you!
@yvrelna
@yvrelna 5 жыл бұрын
I usually prefer to patch using either a context managers or manual start/stop. I'm not really a fan of the decorator version, because they add arguments to test classes, which is just really annoying to work with and because they don't allow you to share the mocking config as easily as the context managers and manual start/stop. Using context manager is also a lot more precise because it makes it really obvious which line of the test function actually requires the patched call. If only one line in the test actually requires patch, then just wrap that line on the context manager, and nothing else. Manual start/stop is great when you want to totally ignore a dependency. Usually helpful for patching out external calls that is slow or have side effects and failure modes you don't really want to deal with.
@karthikvedantham3459
@karthikvedantham3459 3 жыл бұрын
Kudos to Lisa! PyCon
@gaatutube
@gaatutube 4 жыл бұрын
How did she make patched object db_write return 10 so that her assert(x, 10) works. Didn't see any code for that.
@luchoparalosamigos
@luchoparalosamigos 3 жыл бұрын
How do I specify the function that replace the target function?
@hoxas
@hoxas Жыл бұрын
Great talk! Thanks!
@MartinThoma
@MartinThoma 4 жыл бұрын
This talk is awesome! Thank you!
@mostafahassan544
@mostafahassan544 4 жыл бұрын
Great one , thanks Lisa!
@MichaelCampbell01
@MichaelCampbell01 28 күн бұрын
Nice, but she forgot to name the mocked_thing in the resource manager example. Should be `with patch('module.db_write') as mocked_writer:`
@bentaybijamal2299
@bentaybijamal2299 5 жыл бұрын
thanks for your good explanation
@ashrasmun1
@ashrasmun1 4 жыл бұрын
There's one crucial thing missing for me - if I patch it in context manager scope - how can I refer to the mock object? how can I assert how many times was it called? I see mock_* object in two other cases (method and class scope) but I can't see it in CM scope
@dustinalandzes
@dustinalandzes 4 жыл бұрын
burbon ­ with mock.patch(‘module.name’) as mock_module: You can assert on mock_module
@ashrasmun1
@ashrasmun1 4 жыл бұрын
@@dustinalandzes thanks :)
@vasiliyk6775
@vasiliyk6775 6 жыл бұрын
Amazing talk! Thank you!
@atomiclambda
@atomiclambda 5 жыл бұрын
Excellent talk
@ldfsilva
@ldfsilva 6 жыл бұрын
Great talk !
@rahulparshi3172
@rahulparshi3172 4 жыл бұрын
thanks for nice explanation:):)
@johnbalis7898
@johnbalis7898 5 жыл бұрын
super useful; thanks!
@omarocampo7662
@omarocampo7662 5 жыл бұрын
Thanks a lot. REgard from MExico city
@lisaroach9782
@lisaroach9782 6 жыл бұрын
If anyone would like to have the slides I have added them here: drive.google.com/file/d/1QvGv8iw5IDHkUNMUXjLDsm-KVsO3Zuhs/view?usp=sharing
@lightninginmyhands4878
@lightninginmyhands4878 5 жыл бұрын
Thank you!
@danielt8880
@danielt8880 6 жыл бұрын
Wow! Good talk
@anandg2008
@anandg2008 5 жыл бұрын
Awesome
@livethumos
@livethumos 3 жыл бұрын
p
Carl Meyer - Type-checked Python in the real world - PyCon 2018
32:10
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,2 МЛН
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
Happy birthday to you by Secret Vlog
00:12
Secret Vlog
Рет қаралды 6 МЛН
Mocking Strategies in Python
43:42
Excella
Рет қаралды 32 М.
Talk: Harry Percival - Stop Using Mocks (for a while)
44:52
PyCon US
Рет қаралды 14 М.
Edwin Jung - Mocking and Patching Pitfalls - PyCon 2019
47:15
PyCon 2019
Рет қаралды 11 М.
Kyle Knapp - Automating Code Quality - PyCon 2018
29:45
PyCon 2018
Рет қаралды 10 М.
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,2 МЛН