Skip to content

Commit

Permalink
chore: Run tests folder as pytest cases
Browse files Browse the repository at this point in the history
Signed-off-by: Jayson Reis <[email protected]>
  • Loading branch information
jaysonsantos committed Oct 20, 2022
1 parent 801faea commit 807dc10
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,9 +1348,9 @@ def get_podman_args(self, cmd):
xargs.extend(shlex.split(args))
return xargs

def run(self):
def run(self, args=None):
log("podman-compose version: " + __version__)
args = self._parse_args()
args = self._parse_args(args)
podman_path = args.podman_path
if podman_path != "podman":
if os.path.isfile(podman_path) and os.access(podman_path, os.X_OK):
Expand Down Expand Up @@ -1599,7 +1599,7 @@ def _parse_compose_file(self):
self.containers = containers
self.container_by_name = {c["name"]: c for c in containers}

def _parse_args(self):
def _parse_args(self, args=None):
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
self._init_global_parser(parser)
subparsers = parser.add_subparsers(title="command", dest="command")
Expand All @@ -1610,7 +1610,7 @@ def _parse_args(self):
) # pylint: disable=protected-access
for cmd_parser in cmd._parse_args: # pylint: disable=protected-access
cmd_parser(subparser)
self.global_args = parser.parse_args()
self.global_args = parser.parse_args(args)
if self.global_args.version:
self.global_args.command = "version"
if not self.global_args.command or self.global_args.command == "help":
Expand Down
25 changes: 25 additions & 0 deletions pytests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pathlib
import sys

FOLDER_PARAMETER_NAME = "folder"
HERE = pathlib.Path(__file__).parent
ROOT = HERE / ".."
TESTS_FOLDER = ROOT / "tests"

sys.path.append(ROOT)


def pytest_generate_tests(metafunc):
if FOLDER_PARAMETER_NAME in metafunc.fixturenames:
metafunc.parametrize(FOLDER_PARAMETER_NAME, get_fixtures_folder())


def get_fixtures_folder():
for folder in TESTS_FOLDER.glob("*"):
if not folder.is_dir():
continue

if not any(folder.glob("*-compose.y*ml")):
continue

yield str(folder.absolute())
6 changes: 6 additions & 0 deletions pytests/test_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
import podman_compose

def test_case_for(folder):
os.chdir(folder)
podman_compose.podman_compose.run(["build"])
1 change: 1 addition & 0 deletions tests/extends_w_file/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM scratch

0 comments on commit 807dc10

Please sign in to comment.