[TIP] pytest: different tmppath in subprocesses
Bruno Oliveira
nicoddemus at gmail.com
Wed Jun 2 04:16:23 PDT 2021
Hi Harmut,
I would append the os.getpid() to the existing HOME env var, something like
this:
new_home = os.environ["HOME"] + str(os.getpid())
subprocess.run(..., env={ **os.environ, "HOME": new_home})
Hope this helps!
Bruno.
On Wed, Jun 2, 2021 at 8:08 AM Hartmut Goebel <h.goebel at crazy-compilers.com>
wrote:
> Hi,
>
> not sure whether this is the right place to ask pytest questions.
>
> I'm seeking a way to spawn (within a test-case) two processes
> (multiprocess), each having a different "tmppath". The aim is to have a
> different HOME (within tmppath) set in each of the processes.
>
> Any hints? Thanks in advance.
>
> Ideally I can reuse my fixtures I already have for single-process:
>
> @pytest.hookimpl(trylast=True) # run after configure for TempPathFactory
> def pytest_configure(config):
> """
> Change HOME to point to the base directory for this test session.
> """
> global TEST_HOME
> TEST_HOME = config._tmp_path_factory.getbasetemp()
> os.environ["HOME"] = str(TEST_HOME)
>
> @pytest.fixture
> def reset_home(tmp_path):
> os.environ["HOME"] = str(tmp_path)
>
> --
> Regards
> Hartmut Goebel
>
> | Hartmut Goebel | h.goebel at crazy-compilers.com |
> | www.crazy-compilers.com | compilers which you thought are impossible |
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20210602/70c390cf/attachment.html>
More information about the testing-in-python
mailing list