Skip to content
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

Enable integration test workflow to more clearly communicate failure #738

Merged
merged 5 commits into from
Jul 9, 2024
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
4 changes: 3 additions & 1 deletion earthaccess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def search_datasets(count: int = -1, **kwargs: Any) -> List[DataCollection]:
```
"""
if not validate.valid_dataset_parameters(**kwargs):
logger.warn("A valid set of parameters is needed to search for datasets on CMR")
logger.warning(
"A valid set of parameters is needed to search for datasets on CMR"
)
return []
if earthaccess.__auth__.authenticated:
query = DataCollections(auth=earthaccess.__auth__).parameters(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion earthaccess/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(self, auth: Any, pre_authorize: bool = False) -> None:
self.set_requests_session(url)

else:
logger.warn("The current session is not authenticated with NASA")
logger.warning("The current session is not authenticated with NASA")
self.auth = None
self.in_region = self._running_in_us_west_2()

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ line-length = 88
src = ["earthaccess", "stubs", "tests"]

[tool.ruff.lint]
extend-select = ["I", "T20", "D"]
ignore = ["D1", "D205", "D401", "D417"]
extend-select = ["I", "T20", "D", "G"]
ignore = ["D1", "D205", "D401", "D417", "G004"]

[tool.ruff.lint.pydocstyle]
convention = "google"
Expand Down
15 changes: 13 additions & 2 deletions scripts/integration-test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#!/usr/bin/env bash

set -e
set -x
pytest tests/integration --cov=earthaccess --cov=tests/integration --cov-report=term-missing ${@} --capture=no --tb=native --log-cli-level=INFO
RET=$?
set +x

set -e
# NOTE: 99 is a special return code we selected for this case, it has no other meaning.
if [[ $RET == 99 ]]; then
echo -e "\e[0;31mWARNING: The integration test suite has been permitted to return 0 because the failure rate was less than a hardcoded threshold.\e[0m"
echo "For more details, see conftest.py."
exit 0
elif [[ $RET != 0 ]]; then
exit $RET
fi

pytest --cov=earthaccess --cov=tests/integration --cov-report=term-missing ${@} -s --tb=native --log-cli-level=INFO
bash ./scripts/lint.sh
23 changes: 21 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@

@pytest.hookimpl()
def pytest_sessionfinish(session, exitstatus):
if exitstatus == 0:
"""Return exit code 99 if up to N% of tests have failed.

N = ACCEPTABLE_FAILURE_RATE

99 was chosen arbitrarily to avoid conflict with current and future pytest error
codes (https://docs.pytest.org/en/stable/reference/exit-codes.html), and avoid
other exit codes with special meanings
(https://tldp.org/LDP/abs/html/exitcodes.html).

IMPORTANT: This is calculated against every test collected in the session, so the
ratio will change depending on which tests are executed! E.g. executing integration
tests and unit tests at the same time allows more tests to fail than executing
integration tests alone.
"""
if exitstatus != pytest.ExitCode.TESTS_FAILED:
# Exit status 1 in PyTest indicates "Tests were collected and run but some of
# the tests failed". In all other cases, for example "an internal error happened
# while executing the tests", or "test execution interrupted by the user", we
# want to defer to original pytest behavior.
return

failure_rate = (100.0 * session.testsfailed) / session.testscollected
if failure_rate <= ACCEPTABLE_FAILURE_RATE:
session.exitstatus = 0
session.exitstatus = 99
Loading