Skip to content

Commit 4c86007

Browse files
authored
SAT: local python tests log git hash with success or failure (#11497)
* added success check with git hash * code done * added note about local git hash test log * format
1 parent 232d991 commit 4c86007

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/conftest.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
from logging import Logger
1111
from pathlib import Path
12-
from subprocess import run
12+
from subprocess import STDOUT, check_output, run
1313
from typing import Any, List, MutableMapping, Optional
1414

1515
import pytest
@@ -183,3 +183,26 @@ def detailed_logger() -> Logger:
183183
logger.log_json_list = lambda l: logger.info(json.dumps(list(l), indent=1))
184184
logger.handlers = [fh]
185185
return logger
186+
187+
188+
def pytest_sessionfinish(session, exitstatus):
189+
"""Called after whole test run finished, right before returning the exit status to the system.
190+
https://docs.pytest.org/en/6.2.x/reference.html#pytest.hookspec.pytest_sessionfinish
191+
"""
192+
logger = logging.getLogger()
193+
194+
# this is specifically for contributors to run tests locally and show success for a git hash
195+
# therefore if this fails for any reason we just treat as a no-op
196+
try:
197+
result = "PASSED" if session.testscollected > 0 and session.testsfailed == 0 else "FAILED"
198+
print() # create a line break
199+
logger.info(
200+
# session.startdir gives local path to the connector folder, so we can verify which cnctr was tested
201+
f"{session.startdir} - SAT run - "
202+
# using subprocess.check_output to run cmd to get git hash
203+
f"{check_output('git rev-parse HEAD', stderr=STDOUT, shell=True).decode('ascii').strip()}"
204+
f" - {result}"
205+
)
206+
except Exception as e:
207+
logger.info(e) # debug
208+
pass

docs/connector-development/testing-connectors/source-acceptance-tests-reference.md

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ docker build .
3636
Run one of the two scripts in the root of the connector:
3737

3838
* `python -m pytest -p integration_tests.acceptance` - to run tests inside virtual environment
39+
* On test completion, a log will be outputted to the terminal verifying:
40+
* The connector the tests were ran for
41+
* The git hash of the code used
42+
* Whether the tests passed or failed
43+
44+
This is useful to provide in your PR as evidence of the acceptance tests passing locally.
45+
46+
3947
* `./acceptance-test-docker.sh` - to run tests from a docker container
4048

4149
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`:

0 commit comments

Comments
 (0)