ward
ward copied to clipboard
Provide basic builtin fixtures
Currently ward contains no built-in fixtures. There's a few ones that would be nice, if were provided, like pytest tmp_path:
tmp_path
Return a temporary directory path object which is unique to each test
function invocation, created as a sub directory of the base temporary
directory.
By default, a new base temporary directory is created each test session,
and old bases are removed after 3 sessions, to aid in debugging. If
``--basetemp`` is used then it is cleared each session. See :ref:`base
temporary directory`.
The returned object is a :class:`pathlib.Path` object.
I agree this could be useful. I came really close to adding it when writing some of the tests in the Ward test suite.
Mentioned elsewhere that an equivalent of capsys would also be useful.
@darrenburns capsys and caplog are pretty important. I'm am looking into moving to ward, but not having access to these is a bit of a blocker. Do you have a suggestion on how to start setting up a fixture to replicate capsys functionality? I am new to ward and will poke around in the source, but it would be great to have a pointer on where to start with that.
@taranlu-houzz I'm on mobile at the moment, but the Test object in Ward has fields for captured stdout and stderr. We'd need a mechanism for accessing fields on the Test object inside a test. This will probably involve looking up the "currently running test" from the fixture and accessing these fields.
How we find the "current running test" from a fixture... I'm not sure without looking further. I don't think it's possible without a small code change in the internals but would require some investigation.
I just want to note that for the case of tmp_path, I happily include plumbum in my testing dependencies, giving me access to these fine context managers:
from plumbum import local
with local.tempdir() as tmp:
with local.cwd(tmp):
I always prefer their path objects anyway.