From a277e6101828afa58b4b602c4e402259889de81b Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Wed, 16 Nov 2022 07:45:03 +0100 Subject: [PATCH] pytest 7.2 compatibility --- tests/unit/cli_test.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/unit/cli_test.py b/tests/unit/cli_test.py index fa6e767..3d766e8 100644 --- a/tests/unit/cli_test.py +++ b/tests/unit/cli_test.py @@ -1,10 +1,11 @@ +import contextlib import os import shutil import tempfile from io import StringIO +from pathlib import Path import docker -import py import pytest from docker.constants import DEFAULT_DOCKER_API_VERSION @@ -23,11 +24,21 @@ from compose.container import Container from compose.project import Project +@contextlib.contextmanager +def working_directory(path): + cwd = Path.cwd() + os.chdir(path) + try: + yield + finally: + os.chdir(cwd) + + class CLITestCase(unittest.TestCase): def test_default_project_name(self): - test_dir = py._path.local.LocalPath('tests/fixtures/simple-composefile') - with test_dir.as_cwd(): + test_dir = Path('tests/fixtures/simple-composefile') + with working_directory(test_dir): project_name = get_project_name('.') assert 'simple-composefile' == project_name -- 2.38.1