Skip to content

SAT: local python tests log git hash with success or failure #11497

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

Merged
merged 6 commits into from
Mar 29, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
from logging import Logger
from pathlib import Path
from subprocess import run
from subprocess import STDOUT, check_output, run
from typing import Any, List, MutableMapping, Optional

import pytest
Expand Down Expand Up @@ -183,3 +183,26 @@ def detailed_logger() -> Logger:
logger.log_json_list = lambda l: logger.info(json.dumps(list(l), indent=1))
logger.handlers = [fh]
return logger


def pytest_sessionfinish(session, exitstatus):
"""Called after whole test run finished, right before returning the exit status to the system.
https://docs.pytest.org/en/6.2.x/reference.html#pytest.hookspec.pytest_sessionfinish
"""
logger = logging.getLogger()

# this is specifically for contributors to run tests locally and show success for a git hash
# therefore if this fails for any reason we just treat as a no-op
try:
result = "PASSED" if session.testscollected > 0 and session.testsfailed == 0 else "FAILED"
print() # create a line break
logger.info(
# session.startdir gives local path to the connector folder, so we can verify which cnctr was tested
f"{session.startdir} - SAT run - "
# using subprocess.check_output to run cmd to get git hash
f"{check_output('git rev-parse HEAD', stderr=STDOUT, shell=True).decode('ascii').strip()}"
f" - {result}"
)
except Exception as e:
logger.info(e) # debug
pass
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ docker build .
Run one of the two scripts in the root of the connector:

* `python -m pytest -p integration_tests.acceptance` - to run tests inside virtual environment
* On test completion, a log will be outputted to the terminal verifying:
* The connector the tests were ran for
* The git hash of the code used
* Whether the tests passed or failed

This is useful to provide in your PR as evidence of the acceptance tests passing locally.


* `./acceptance-test-docker.sh` - to run tests from a docker container

If the test fails you will see detail about the test and where to find its inputs and outputs to reproduce it. You can also debug failed tests by adding `—pdb —last-failed`:
Expand Down