相关疑难解决方法(0)

@Patch装饰器与pytest fixture不兼容

当使用与pytest fixture集成的mock包中的patch decorator时,我遇到了一些神秘的东西.

我有两个模块

    -----test folder
          -------func.py
          -------test_test.py
Run Code Online (Sandbox Code Playgroud)

在func.py中:

    def a():
        return 1

    def b():
        return a()     
Run Code Online (Sandbox Code Playgroud)

在test_test.py中

    import pytest
    from func import a,b
    from mock import patch,Mock

    @pytest.fixture(scope="module")
    def brands():
        return 1


    mock_b=Mock()

    @patch('test_test.b',mock_b)
    def test_compute_scores(brands):                 
         a()
Run Code Online (Sandbox Code Playgroud)

似乎补丁装饰与pytest fixture不兼容.有没有人对此有所了解?Tnanks

python mocking pytest

25
推荐指数
5
解决办法
1万
查看次数

标签 统计

mocking ×1

pytest ×1

python ×1