Skip to content

Commit

Permalink
Recognize pytest (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Apr 12, 2021
1 parent 6ef6061 commit a2e7305
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions playbooks/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
url: https://github.com/cookiecutter/cookiecutter.git
- name: typeshed
url: https://github.com/python/typeshed.git
- name: flask-babel
url: https://github.com/python-babel/flask-babel.git
tasks:

- name: Clone repo
Expand Down
1 change: 1 addition & 0 deletions samples/integration/ansible-lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ py38-devel
py39-ansible29
py39-core
py39-devel
test
test-requirements
test-setup
uninstall
Expand Down
5 changes: 5 additions & 0 deletions samples/integration/flask-babel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
install
test
uninstall
up
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mk_tools =
make=mk.tools.make:MakeTool
npm=mk.tools.npm:NpmTool
pypackage=mk.tools.py_package:PyPackageTool
pytest=mk.tools.pytest:PyTestTool
pre-commit=mk.tools.pre_commit:PreCommitTool
shell=mk.tools.shell:ShellTool
tox=mk.tools.tox:ToxTool
Expand Down
5 changes: 3 additions & 2 deletions src/mk/tools/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def up(self):
result = run_or_fail(["gh", "pr", "list", "-S", f"head:{repo.active_branch}"])
if result.returncode == 0:
pr_list = []
for line in result.stdout.splitlines():
pr_list.append(line.split("\t")[0])
if result.stdout:
for line in result.stdout.splitlines():
pr_list.append(line.split("\t")[0])
if len(pr_list) == 0:
logging.debug("Existing PR not found, creating one.")
commit = repo.head.commit
Expand Down
40 changes: 40 additions & 0 deletions src/mk/tools/pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import sys
from typing import List, Optional

from mk.exec import run_or_fail
from mk.tools import Action, Tool


class PyTestTool(Tool):
"""Expose test command if pytest config is detected."""

name = "pytest"

def __init__(self) -> None:
super().__init__(self)

def run(self, action: Optional[Action] = None) -> None:
if not action:
return
if action.name == "test":
cmd = [sys.executable, "-m", "pytest"]
run_or_fail(cmd, tee=True)

def is_present(self, path: str) -> bool:
for name in ("pytest.ini",):
if os.path.isfile(name):
return True
return False

def actions(self) -> List[Action]:
actions = []
actions.append(
Action(
name="test",
tool=self,
description="Run pytest",
)
)

return actions

0 comments on commit a2e7305

Please sign in to comment.