久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

夾具上的 py.test 補丁

py.test patch on fixture(夾具上的 py.test 補丁)
本文介紹了夾具上的 py.test 補丁的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用以下內容來模擬 py.test 測試的常量值:

I use the following to mock constant values for a test with py.test:

@patch('ConstantsModule.ConstantsClass.DELAY_TIME', 10)
def test_PowerUp():
    ...
    thing = Thing.Thing()
    assert thing.a == 1

這模擬了測試和 Thing 中使用的 DELAY_TIME,這是我所期望的.

This mocks DELAY_TIME as used in both the test, and in Thing, which is what I expected.

我想對這個文件中的所有測試都這樣做,所以我嘗試了

I wanted to do this for all the tests in this file, so I tried

@patch('ConstantsModule.ConstantsClass.DELAY_TIME', 10)
@pytest.fixture(autouse=True)
def NoDelay():
    pass

但這似乎沒有同樣的效果.

But that doesn't seem to have the same effect.

這是一個類似的問題:pytest fixture中的pytest-mock mocker,但模擬似乎在那里以非裝飾方式完成.

Here is a similar question: pytest-mock mocker in pytest fixture, but the mock seems done in a non-decorator way there.

推薦答案

我想說通過裝飾器打補丁并不是這里的最佳方法.我會使用上下文管理器:

I'd say patching via decorator is not the optimal approach here. I'd use the context manager:

import pytest
from unittest.mock import patch


@pytest.fixture(autouse=True)
def no_delay():
    with patch('ConstantsModule.ConstantsClass.DELAY_TIME', 10):
        yield

這樣,補丁在測試拆解時完全恢復.

This way, patching is cleanly reverted on test teardown.

這篇關于夾具上的 py.test 補丁的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點小數點/精度)
Converting Float to Dollars and Cents(將浮點數轉換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計算可以返回 NaN?)
Python float to ratio(Python浮動比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 国产成人精品免费视频大全最热 | 亚洲精品久久久蜜桃网站 | 国产精品免费在线 | 一区二区国产精品 | 亚洲色图网址 | 在线观看你懂的网站 | 国产一区二区视频免费在线观看 | 羞羞视频网站免费观看 | 在线高清免费观看视频 | 亚洲视频在线看 | 欧美综合久久久 | 99精品国产一区二区三区 | 一区二区精品电影 | 日韩超碰在线 | 免费黄色的视频 | 日韩av一区二区在线观看 | 一区二区三区国产精品 | 久久久精品久久久 | 日韩成人精品在线观看 | 国产成人精品久久二区二区91 | av在线播放一区二区 | 欧美日日 | 亚洲一av| 亚洲成人黄色 | 国产日韩久久 | 国产日韩精品一区二区 | 国产激情在线 | 日韩在线免费视频 | 国产成人精品视频在线观看 | 国产激情视频 | 国产精品日韩在线观看一区二区 | 亚洲精品视频在线看 | 91精品国产色综合久久不卡98 | 特黄毛片 | 成人综合在线视频 | 国产精品2 | 天天躁人人躁人人躁狂躁 | 国产黄色大片 | 91综合网 | 男女精品久久 | www.788.com色淫免费 |