ward icon indicating copy to clipboard operation
ward copied to clipboard

Provide basic builtin fixtures

Open Prof-Bloodstone opened this issue 4 years ago • 5 comments
trafficstars

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.

Prof-Bloodstone avatar May 16 '21 19:05 Prof-Bloodstone

I agree this could be useful. I came really close to adding it when writing some of the tests in the Ward test suite.

darrenburns avatar May 17 '21 20:05 darrenburns

Mentioned elsewhere that an equivalent of capsys would also be useful.

darrenburns avatar Jun 10 '21 09:06 darrenburns

@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 avatar Jun 15 '21 20:06 taranlu-houzz

@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.

darrenburns avatar Jun 15 '21 21:06 darrenburns

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.

AndydeCleyre avatar Nov 22 '22 19:11 AndydeCleyre