Skip to content

Commit

Permalink
SAT: local python tests log git hash with success or failure (airbyte…
Browse files Browse the repository at this point in the history
…hq#11497)

* added success check with git hash

* code done

* added note about local git hash test log

* format
  • Loading branch information
Phlair authored Mar 29, 2022
1 parent 232d991 commit 4c86007
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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

0 comments on commit 4c86007

Please sign in to comment.