Skip to content

Add pytest target #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/actions/pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Run unit tests."""

# standard library
import os
import subprocess

# third party
import pytest

# first party
import delphi.github_deploy_repo.file_operations as file_operations

class Plugin:
def __init__(self):
self.summary={
"passed":0,
"failed":0,
"skipped":0,
"errors":0
}
def pytest_runtest_logreport(self, report):
self.summary[report.outcome] += 1
def pytest_internalerror(self, *args, **kwargs):
self.summary["errors"] += 1
def pytest_exception_interact(self, *args, **kwargs):
self.summary["errors"] += 1

def pytest(repo_link, commit, path, row, substitutions):
# pytest [dir]

# parse arguments
if 'dir' in row:
location = file_operations.get_file(row['dir'], path, substitutions)[0]
else:
location = os.path.join(path, 'tests')
pattern = '^(test_.*|.*_test)\\.py$'

# run tests and gather results
p = Plugin()
pytest.main([location, 'no:terminal'], plugins=[p])
bad = p.summary['failed'] + p.summary['errors']
if bad > 0:
raise Exception('%d test(s) did not pass' % bad)
elif p.summary['passed'] == 0:
print('no tests found')
else:
print('%d test(s) passed!' % p.summary['passed'])
2 changes: 2 additions & 0 deletions src/github_deploy_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from delphi.github_deploy_repo.actions.copymove import copymove
from delphi.github_deploy_repo.actions.minimize_js import minimize_js
from delphi.github_deploy_repo.actions.py3test import py3test
from delphi.github_deploy_repo.actions.pytest import pytest
import delphi.github_deploy_repo.database as database
import delphi.operations.secrets as secrets
import delphi.utils.extractor as extractor
Expand Down Expand Up @@ -111,6 +112,7 @@ def execute(repo_link, commit, path, config):
'compile-coffee': compile_coffee,
'minimize-js': minimize_js,
'py3test': py3test,
'pytest': pytest
}
for (idx, row) in enumerate(actions):
# each row should be either: a map/dict/object with a string field named
Expand Down