There are some pytest plugins that will handle this for you. In particular
pytest-httpserver is implemented the way you want, where it'll start the server
once at the beginning of your test session and keep it running. I'd suggest
checking that out.
Though in general, I think it's better not to worry too much about whether
resources are allocated freshly for each test or not, unless you find that your
test suite is unacceptably slow because of that resource allocation. It's all
too easy to have different tests interfere with each other if you reuse
resources, unless you're very careful.
David
-------- Original Message --------
On 6/20/25 6:31 AM, Skip Montanaro via code-quality wrote:
> I'm struggling trying to understand how Pytest's fixtures can be used to
> facilitate setup and teardown of long-running resource servers. For example,
> I want to fire up a little web server (because the tool I'm testing queries a
> web server IRL) to serve up some simple content. I don't want to start it for
> each test case, just once and the start, then stop it at the end. All the
> notes/documentation I've found seem to emphasize fixture's ease-of-use by
> "requesting" them on a per-test-case basis.
>
> Can someone point me to a tutorial which explains how to properly set up and
> tear down a service at the beginning and end of a test run?
>
> Thx,
>
> Skip
_______________________________________________
code-quality mailing list -- code-quality@python.org
To unsubscribe send an email to code-quality-le...@python.org
https://mail.python.org/mailman3//lists/code-quality.python.org
Member address: arch...@mail-archive.com