и посмотреть медиа
Zen of Python - Zen
и посмотреть медиа
Complete guide to Python philosophy and practice in one channel.
Complete guide to Python philosophy and practice in one channel.
Zen of Python - channel dedicated to Python philosophy and practices. Lessons, scripts, best practices and materials for mastering the language in Telegram.
Почему mock.patch не подменяет функцию в Python После from os import listdir имя listdir привязано в модуле product. Последующая подмена os.listdir эту привязку не меняет, поэтому код продолжает вызывать product.listdir. mock.patch работает как временное присваивание: заменяет имя по указанному пути, а после блока with возвращает исходное значение. Практическое правило: подменяйте имя там, где его ищет тестируемый код. Здесь нужен mock.patch("product.listdir"). Он изменит поведение только product.py, не затрагивая другие модули. В статье Why your mock doesn’t work механизм разобран на двух способах импорта и схемах связей между именами.
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!