久久久久久久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 的意思不同)
主站蜘蛛池模板: 久草视频免费在线 | 欧美日韩在线一区 | 国产亚洲一区二区三区 | 国产福利91精品一区二区三区 | 成人小视频在线观看 | 亚洲免费专区 | 日韩不卡在线观看 | 日日操天天操 | 黄色av免费观看 | 午夜精品视频在线 | 日韩中文av | 欧美一区二区三区不卡 | 黄色大片免费在线观看 | 黄色小视频在线免费观看 | 亚洲 欧美 日韩 在线 | 国产欧美精品一区二区三区 | 六月丁香综合 | av网站在线播放 | 久草福利视频 | 99久久婷婷国产综合精品草原 | 久久精品欧美一区二区 | 欲望岛av| 精品1区2区3区 | 在线欧美| 天天舔天天操 | 欧美激情五月 | 91欧美日韩 | 欧美一区二区三区在线观看 | 久久久久久久 | 一级理论片 | 免费观看的黄色网址 | 国产精品99久久久久久www | 久艹视频在线观看 | 97精品国产97久久久久久免费 | 日本黄色免费网站 | 97精品在线观看 | 国产精品手机在线 | 久久精品视频一区二区 | 日韩一级淫片 | 国产激情一区二区三区 | 欧美a级黄色片 |