Skip to content

Is it possible to use the library with pytest.fixture and MagicMock? #31

Answered by zhukovgreen
samuelint asked this question in Q&A
Discussion options

You must be logged in to vote

Next time please care about others' time and give a reproducible code that I can run locally without any extra editions.

From what I see, there is no problem with pytest-when in this case and it can support your use case without any limitations.

The core problem in your code was wrong call to when fixture and fixtures compositions. when fixture, identically to unittest.mock.patch.object, takes Klass as target
(type hints are (cls: _TargetClsType, method: str)). So instead of when(agent, ...) you need to have when(CompiledGraph, ...).

Then you had issue with fixtures composition in your fixtures.

Working solution

from typing import NamedTuple

import pytest

from pytest_mock import MockerF…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by samuelint
Comment options

You must be logged in to vote
1 reply
@zhukovgreen
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants