[py-dev] Using funcargs (monkeypatch, tmpdir) during setup
Virgil Dupras
hsoft at hardcoded.net
Sun Jan 2 17:25:45 CET 2011
Hi all, it's me again.
I'm wondering what's the common pattern of pytest users regarding the use of monkey-patching and temporary directories in setup functions. I already have my own "home-brewed" (again!) mechanism for that, but I want to "pytest-ify" the way I write tests.
So far, the only solution I can come up with is to have all tests use the funcarg(s) and pass them to the setup function when they're called. Example:
def my_setup(monkeypatch, tmpdir):
moneypatch.setattr(module, 'something', foo)
tmpdir.mkdir('bar')
def test1(monkeypatch, tmpdir):
my_setup(monkeypatch, tmpdir)
# test stuff
def test2(monkeypatch, tmpdir):
my_setup(monkeypatch, tmpdir)
# test stuff
This code works, but it seems repetitive to me, especially if only the setup use the monkeypatching and tmpdir, not the tests themselves. What are other pytest users doing in these situations? Is there some clever trick I'm unaware of? I'm certainly not the only person in that situation, am I?
Thanks,
Virgil Dupras
More information about the Pytest-dev
mailing list