나는 모듈 설정 거칠게 다음과 같다:
# foo.py
def generate_things_based_on_other_things():
# some nasty things here
# bar.py
from foo import generate_things_based_on_other_things as generate
def coo():
generate()
# conftest.py
import pytest
@pytest.fixture(autouse=True)
def patch_generate(monkeypatch):
def mock_generate():
print("hello!")
monkeypatch.setattr("app.bar.generate", mock_generate)
# test_bar.py
from bar import coo
def test_coo():
coo()
당으로 이 대답을 확인 했 monkeypatch 실제 가져오스의 기능입니다. 다른 어떤 경로를 던졌 "does not exist on module"
오류가 있습니다.
그러나 때 나는 실행하는 테스트를 내가 오류가 있기 때문에,본래 기능 generate
가 호출되는 것에도 불구하고 monkeypatched.
를 알아낼 수 없습니다 왜 이 패치지 않을 것 지팡이의 방법으로 기대됩니다.
제가 기대하는 이 시험을 인쇄"안녕하세요!".