How to Test Python's Random Module
Автор: Pybites
Загружено: 2023-05-23
Просмотров: 655
Описание:
In this video you'll learn how to effectively test the Python random module using pytest.
We cover strategies for testing code that involves picking random emails with the random sample function (code from previous video put into functions: • Using a bit of Python to get random emails... )
We demonstrate the use of len() and all(), but then refactor the tests to use random.seed() to make random functions predictable, ensuring consistent results for testing.
We put random.seed() in a pytest fixture, using autouse=True to run the fixture automatically (that is, we don't pass it into the test function).
Here is an article on pytest fixtures if you're new to them: https://pybit.es/pytest-fixtures.html
A follow up video could be to refactor this test again showing how you could use mocking, just comment below if interested, as well for more Standard Library modules and testing videos ... 💡
Code:
get random emails: https://gist.github.com/bbelderbos/5d...
final tests: https://gist.github.com/bbelderbos/b9...
---
Learn more about Pybites / what we do: https://pybit.es
Get our weekly developer / mindset emails: https://pybit.es/friends/
Join our Slack community: https://pybit.es/community/
And last but not least, we appreciate any feedback to make our YouTube content better 💡
https://form.jotform.com/230941798741062 🙏
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: