Ask Your Question
0

Why is Pytest monkeypatch not functioning on a function that has been imported?

asked 2023-06-25 10:54:39 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-25 11:15:01 +0000

lakamha gravatar image

There could be several reasons why pytest monkeypatch is not working on an imported function:

  1. The module containing the function may have already been imported before the pytest session started. In this case, the function's original implementation may have already been loaded into memory, and the monkeypatched version will not have any effect.

  2. The function may be defined in a way that is not compatible with pytest monkeypatch. For example, if the function relies on global state or executes external code, monkeypatching may not be able to modify its behavior.

  3. The code importing the function may not be designed to allow monkeypatching. Some libraries or frameworks may not support monkeypatching, or may require additional configuration to enable it.

To diagnose the issue, it may be helpful to inspect the function's implementation and the code importing it, as well as any relevant documentation or example code for the library or framework in use. It may also be useful to try alternative monkeypatching techniques or to use a different testing approach altogether.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-25 10:54:39 +0000

Seen: 13 times

Last updated: Jun 25 '23