[TIP] pytest: different tmppath in subprocesses

Bruno Oliveira nicoddemus at gmail.com
Wed Jun 2 07:56:28 PDT 2021


On Wed, Jun 2, 2021 at 11:42 AM Hartmut Goebel h.goebel at crazy-compilers.com
<http://mailto:h.goebel@crazy-compilers.com> wrote:

After trying more, I can rephrase my question:
>
Ahh now I got what you mean, thanks for clarifying.

Is there some way to postpone execution of fixtures until into the spawned
> process?
>
> Calling fixtures as functions would have been an options, but has been
> disabled in pytest 4.0.
>
One solution would be to do a small refactoring in your fixtures, to also
expose their functionality as functions. For example:

@pytest.fixturedef resource(tmp_path):
    result = Resource(tmp_path)
    yield result
    result.close()

Into:

@contextmanagerdef using_resource(path):
    result = Resource(path)
    try:
        yield result
    finally:
        result.close()
@pytest.fixturedef resource(tmp_path):
    with using_resource(tmp_path) as result:
        yield result

Cheers,
Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20210602/e6b5f020/attachment-0001.htm>


More information about the testing-in-python mailing list