diff --git a/airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/conftest.py b/airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/conftest.py index 11eed204be6ae..52d046b7a0153 100644 --- a/airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/conftest.py +++ b/airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/conftest.py @@ -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 @@ -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 diff --git a/docs/connector-development/testing-connectors/source-acceptance-tests-reference.md b/docs/connector-development/testing-connectors/source-acceptance-tests-reference.md index 1910ec5a2e1a4..0e6f3c8e088fe 100644 --- a/docs/connector-development/testing-connectors/source-acceptance-tests-reference.md +++ b/docs/connector-development/testing-connectors/source-acceptance-tests-reference.md @@ -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`: