mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
tests: Run each test in separate config/cache dirs
Run each CLI command in a separate config/cache dir, to avoid leaks between tests. Moreover, this way we are able to check the contents of the config/cache dirs for a single CLI run.
This commit is contained in:
parent
44c324f9ac
commit
18bc77332d
1 changed files with 20 additions and 12 deletions
|
@ -10,6 +10,7 @@ import tempfile
|
|||
import traceback
|
||||
from pathlib import Path
|
||||
from typing import Sequence
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner, Result
|
||||
|
@ -129,6 +130,8 @@ class TestCli(TestBase):
|
|||
if os.environ.get("DUMMY_CONVERSION", False):
|
||||
args = ("--unsafe-dummy-conversion", *args)
|
||||
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
tmp_dir = Path(t)
|
||||
# TODO: Replace this with `contextlib.chdir()` [1], which was added in
|
||||
# Python 3.11.
|
||||
#
|
||||
|
@ -137,6 +140,11 @@ class TestCli(TestBase):
|
|||
if tmp_path is not None:
|
||||
cwd = os.getcwd()
|
||||
os.chdir(tmp_path)
|
||||
|
||||
with mock.patch(
|
||||
"dangerzone.isolation_provider.container.get_tmp_dir",
|
||||
return_value=t,
|
||||
):
|
||||
result = CliRunner().invoke(cli_main, args)
|
||||
finally:
|
||||
if tmp_path is not None:
|
||||
|
|
Loading…
Reference in a new issue