Python tests | Pytest Mock and Patch

preview_player
Показать описание
Unit Tests (Pytest in this case) can save you time. Here we look at how to use mock and patch with some code to make requests and then I disconnect from the internet and my 'parse' function still passes the test.

This is intended as a basic, but useful intro to the world of Pytest and Mock and Patch.

Also includes a few tips on folder structure and using __init__.py

Use this link for excellent hosting with Python installed :

👍 Become a patron 👍

Buy Dr Pi a coffee (or Tea)

Thumbs up yeah? (cos Algos..)

Python Tutorial
Pytest vscode
Pytest tutorial
Pytest mock requests example
Pytest patch

#pytest #requests #pythonprogramming
Рекомендации по теме
Комментарии
Автор

This is the easiest and clearest explanation that i've seen so far!! It helped me immensely, thank you so much!!!

shadelmendez
Автор

Very, very good explanation. You did a great job of explaning how mocks work, and showing their value in a very practical way. Thanks!

rosscoguitar
Автор

This can be pretty confusing for those of us starting out with mock and patch. This was really clear. Thanks. (Thumbs up, subscribed).

jjones
Автор

Good to learn from "Jean Claude Van Damme" :) On serious note, please post more pytest, you method of teaching is v good.

paracha
Автор

Hi when running the tests I get error "modulenotfounderror no module named app" . I know there is something wrong with the relative imports? but I followed your structure exactly

corybilyeu
Автор

Thank you man! Nice domain of the subject

sebastiancontreras
Автор

since app is one directory up from tests/test_bcd.py, how can you import it such as from app.fetch_www import parse?

This would need to go one directory up first?

corybilyeu
Автор

When I enter this line: "from app.fetch_www import parse". 
It shows the error: Import "app.fetch_www"cannot be resolved. Pylance (reportMissingImports). 
Do you know how to fix?

thongtranquoc
Автор

How do we test a function that needs arguments with this method ?

nikosgeorgantas
Автор

I am getting attribute error for the file path

kirubababu
Автор

came because the girl, stayed because of the knowledge

paulosantana
Автор

The amount of style is distractful against the content!

chobblegobbler