Почему @patch из unittest.mock ломает вам тесты, если не указать autospec=True

Привет, Хабр! Сегодня разберёмся, почему без autospec=True ваш безобидный @patch из unittest.mock может превратить зелёный репорт в мину замедленного действия. Смысл patch() прост: отрезаем внешний мир, подсовываем фейковый объект и гоняем логику изолированно. Но если не включить autospec , мок превращается в пластилин — к нему прилипает любой метод, любые аргументы, и тесты радостно хлопают ладоши, даже когда в коде опечатка или нарушена сигнатура.

https://habr.com/ru/companies/otus/articles/901534/

#python #моки #pytest #модульное_тестирование #python_qa_engineer #test_isolation

Почему @patch из unittest.mock ломает вам тесты, если не указать autospec=True

Привет, Хабр! Сегодня — разберёмся, почему без autospec=True ваш безобидный @patch из unittest.mock может превратить зелёный репорт в мину замедленного действия. Смысл patch() прост:...

Хабр
I'm adding resources for future reading for mine and Marie's #Python #packaging tutorial for #PyConUS, and I realised that I don't know any good #pytest tutorials for beginners. Does anyone have any reccommendations?

Protip: jeżeli piszecie test jednostkowy, i ten test dosłownie powtarza kod testowanej funkcji, to nie testujecie nic.

#Python #PyTest

Protip: if your unit test pretty much literally repeats what the tested function does, it's not testing anything.

#Python #PyTest

I just decided to piggy back the @pragprog sale and offer 40% off of courses at https://courses.pythontest.com with code 2025TESTING now through April 22 #python #pytest https://fosstodon.org/@brianokken/114344124201148334
Python Testing with pytest, 2nd edition
40% Off – This Week Only!
Code: 2025testing at checkout
https://pragprog.com/titles/bopytest2/python-testing-with-pytest-second-edition/
#Python #pytest
Python Testing with pytest, Second Edition

Create efficient, elegant software tests in pytest, Python's most powerful testing framework.

I'm a bit stumped, ideas?

in a #pytest framework i have a test that relies on a few api calls that i all mocked out reliably using responses.RequestsMock and then processes the result. When i run the test in my local development environment it reliably passes. But in our CI pipeline, it usually fails with slightly different numeric results, but sometimes also just passes. The difference between the numeric results is restricted to a few entries, and too large for floating point error

#python

Here is my example of testing PyZMQ client and server code with pytest and pytest-mock. I haven't found much information on this topic. Anyone else have examples of testing PyZMQ code? https://gavinw.me/pythonic/pyzmq/test-client-server.html

#python #pytest #zeromq #pyzmq

Pythonic Programming

Testing a PyZMQ Client and Server

pytest: running multiple tests with names that might contain spaces

You most certainly know that you can run a single test in entire suite by passing the full path: PRODUCT_ENV='stage' pytest -v --critical tests/test_mod.py::test_func[x1] This gets old when you want to run around 3 or more tests. In that case, you might end up putting …

Mirek Długosz personal website