久久久久久久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 的意思不同)
主站蜘蛛池模板: 亚洲小视频在线观看 | 国产精品a久久久久 | 免费看国产a | 黄色在线免费观看 | 成人国产精品免费观看 | 欧美成人一区二区 | 成人二区| 久久综合婷婷 | 黄视频网站在线 | 欧美一区中文字幕 | 一区二区三区国产 | 性色av网站 | 亚洲网站在线观看 | 成人激情视频免费在线观看 | 特级丰满少妇一级aaaa爱毛片 | 亚洲免费在线观看视频 | 欧美精品三区 | 日韩中文字幕在线视频 | 亚洲九九色 | 中文字幕成人 | 91一区二区三区在线观看 | 日韩中文视频 | 国产1区 | 粉嫩一区二区三区国产精品 | 精品一区二区久久久久久久网站 | 国产精品久久久久无码av | 久久一| 国产成人精品一区二区三区网站观看 | 成人免费一区二区三区视频网站 | 国产91精品久久久久久久网曝门 | 亚洲一区视频在线 | 91精品亚洲 | 国产精品呻吟久久av凹凸 | 狠狠狠| 国产精品高清在线 | 人人天天操 | 色性av | 国产精品一区久久久 | 综合网伊人 | 久久国产精品一区二区 | 91久久国产综合久久 |