Reputation: 361
I have a function that uses os.walk
and I want to test it using monkeypatching (PyTest). I don't know how to use monkeypatch.setattr
.
Upvotes: 1
Views: 598
Reputation: 80811
To achieve correct mock of the os.walk, you have to use
monkeypatch.setattr(os, "walk", function_that_will_simulate_os_walk_iterator)
The function_that_will_simulate_os_walk_iterator
should return a list of tuples (root, dirs, files)
for each simulated file.
Upvotes: 2