Add the ability to run test patterns. (#454)

Signed-off-by: dblock <dblock@amazon.com>
This commit is contained in:
Daniel (dB.) Doubrovkine
2023-07-26 12:18:45 -05:00
committed by GitHub
parent 42852d0d53
commit e022932ed1
9 changed files with 72 additions and 49 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ if [[ -z $opensearch_node_name ]]; then
fi fi
export script_path=$(dirname $(realpath -s $0)) export script_path=$(dirname $(realpath $0))
source $script_path/functions/cleanup.sh source $script_path/functions/cleanup.sh
source $script_path/functions/wait-for-container.sh source $script_path/functions/wait-for-container.sh
trap "cleanup_trap ${network_name}" EXIT trap "cleanup_trap ${network_name}" EXIT
+1 -1
View File
@@ -24,7 +24,7 @@
# Bootstrap # Bootstrap
# ------------------------------------------------------- # # ------------------------------------------------------- #
script_path=$(dirname "$(realpath -s "$0")") script_path=$(dirname "$(realpath "$0")")
repo=$(realpath "$script_path/../") repo=$(realpath "$script_path/../")
# shellcheck disable=SC1090 # shellcheck disable=SC1090
+1 -1
View File
@@ -5,7 +5,7 @@
# #
# Export the NUMBER_OF_NODES variable to start more than 1 node # Export the NUMBER_OF_NODES variable to start more than 1 node
script_path=$(dirname $(realpath -s $0)) script_path=$(dirname $(realpath $0))
source $script_path/functions/imports.sh source $script_path/functions/imports.sh
set -euo pipefail set -euo pipefail
+3
View File
@@ -38,7 +38,10 @@ docker run \
--env "TEST_SUITE=${TEST_SUITE}" \ --env "TEST_SUITE=${TEST_SUITE}" \
--env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \ --env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \
--env "TEST_TYPE=server" \ --env "TEST_TYPE=server" \
--env "TEST_PATTERN=${TEST_PATTERN}" \
--name opensearch-py \ --name opensearch-py \
--rm \ --rm \
opensearch-project/opensearch-py \ opensearch-project/opensearch-py \
python setup.py test python setup.py test
unset TEST_PATTERN
+2 -1
View File
@@ -9,6 +9,7 @@ export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=Urllib3HttpConnection
export CLUSTER="${CLUSTER:-opensearch}" export CLUSTER="${CLUSTER:-opensearch}"
export SECURE_INTEGRATION="${1:-false}" export SECURE_INTEGRATION="${1:-false}"
export OPENSEARCH_VERSION="${2:-latest}" export OPENSEARCH_VERSION="${2:-latest}"
export TEST_PATTERN="${3:-}"
if [[ "$SECURE_INTEGRATION" == "true" ]]; then if [[ "$SECURE_INTEGRATION" == "true" ]]; then
export OPENSEARCH_URL_EXTENSION="https" export OPENSEARCH_URL_EXTENSION="https"
else else
@@ -21,7 +22,7 @@ if [[ "$OPENSEARCH_VERSION" == *"SNAPSHOT" ]]; then
fi fi
echo -e "\033[1m>>>>> Unreleased is $IS_UNRELEASED >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m" echo -e "\033[1m>>>>> Unreleased is $IS_UNRELEASED >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
script_path=$(dirname $(realpath -s $0)) script_path=$(dirname $(realpath $0))
source $script_path/functions/imports.sh source $script_path/functions/imports.sh
set -euo pipefail set -euo pipefail
+1
View File
@@ -19,6 +19,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added samples ([#447](https://github.com/opensearch-project/opensearch-py/pull/447)) - Added samples ([#447](https://github.com/opensearch-project/opensearch-py/pull/447))
- Improved CI performance of integration with unreleased OpenSearch ([#318](https://github.com/opensearch-project/opensearch-py/pull/318)) - Improved CI performance of integration with unreleased OpenSearch ([#318](https://github.com/opensearch-project/opensearch-py/pull/318))
- Added k-NN guide and samples ([#449](https://github.com/opensearch-project/opensearch-py/pull/449)) - Added k-NN guide and samples ([#449](https://github.com/opensearch-project/opensearch-py/pull/449))
- Added the ability to run tests matching a pattern to `.ci/run-tests` ([#454](https://github.com/opensearch-project/opensearch-py/pull/454))
### Changed ### Changed
- Moved security from `plugins` to `clients` ([#442](https://github.com/opensearch-project/opensearch-py/pull/442)) - Moved security from `plugins` to `clients` ([#442](https://github.com/opensearch-project/opensearch-py/pull/442))
### Deprecated ### Deprecated
+12
View File
@@ -17,6 +17,8 @@ $ python --version
Python 3.11.1 Python 3.11.1
``` ```
You can install dev requirements with `pip install -r dev-requirements.txt`, but it's better to use the docker setup described below.
Install [Nox](https://nox.thea.codes/en/stable/) for task management. Install [Nox](https://nox.thea.codes/en/stable/) for task management.
``` ```
@@ -69,6 +71,16 @@ The following example runs tests against the latest SNAPSHOT build of OpenSearch
./.ci/run-tests opensearch false SNAPSHOT ./.ci/run-tests opensearch false SNAPSHOT
``` ```
You can also run individual tests matching a pattern (`pytest -k [pattern]`).
```
./.ci/run-tests true 1.3.0 test_no_http_compression
test_opensearchpy/test_connection.py::TestUrllib3Connection::test_no_http_compression PASSED [ 33%]
test_opensearchpy/test_connection.py::TestRequestsConnection::test_no_http_compression PASSED [ 66%]
test_opensearchpy/test_async/test_connection.py::TestAIOHttpConnection::test_no_http_compression PASSED [100%]
```
Note that integration tests require docker to be installed and running, and downloads quite a bit of data from over the internet and hence take few minutes to complete. Note that integration tests require docker to be installed and running, and downloads quite a bit of data from over the internet and hence take few minutes to complete.
## Linter ## Linter
+1
View File
@@ -6,6 +6,7 @@ mock
sphinx<7.1 sphinx<7.1
sphinx_rtd_theme sphinx_rtd_theme
jinja2 jinja2
pytz
# No wheels for Python 3.10 yet! # No wheels for Python 3.10 yet!
numpy; python_version<"3.10" numpy; python_version<"3.10"
+50 -45
View File
@@ -111,58 +111,63 @@ def run_all(argv=None):
if environ.get("OPENSEARCH_URL", "").startswith("https://"): if environ.get("OPENSEARCH_URL", "").startswith("https://"):
secured = True secured = True
ignores = [] # check TEST_PATTERN env var for specific test to run
# Python 3.6+ is required for async test_pattern = environ.get("TEST_PATTERN")
if sys.version_info < (3, 6): if test_pattern:
ignores.append("test_opensearchpy/test_async/") argv.append("-k %s" % test_pattern)
else:
ignores = []
# Python 3.6+ is required for async
if sys.version_info < (3, 6):
ignores.append("test_opensearchpy/test_async/")
ignores.extend(
[
"test_opensearchpy/test_server/",
"test_opensearchpy/test_server_secured/",
"test_opensearchpy/test_async/test_server/",
"test_opensearchpy/test_async/test_server_secured/",
]
)
# Jenkins/Github actions, only run server tests
if environ.get("TEST_TYPE") == "server":
test_dir = abspath(dirname(__file__))
if secured:
argv.append(join(test_dir, "test_server_secured"))
if sys.version_info >= (3, 6):
argv.append(join(test_dir, "test_async/test_server_secured"))
ignores.extend(
[
"test_opensearchpy/test_server/",
"test_opensearchpy/test_async/test_server/",
]
)
else:
argv.append(join(test_dir, "test_server"))
if sys.version_info >= (3, 6):
argv.append(join(test_dir, "test_async/test_server"))
ignores.extend(
[
"test_opensearchpy/test_server_secured/",
]
)
# There are no plugins for unreleased versions of opensearch
if environ.get("OPENSEARCH_VERSION") == "SNAPSHOT":
ignores.extend( ignores.extend(
[ [
"test_opensearchpy/test_server/test_plugins/", "test_opensearchpy/test_server/",
"test_opensearchpy/test_async/test_server/test_plugins/", "test_opensearchpy/test_server_secured/",
"test_opensearchpy/test_async/test_server/",
"test_opensearchpy/test_async/test_server_secured/",
] ]
) )
if ignores: # Jenkins/Github actions, only run server tests
argv.extend(["--ignore=%s" % ignore for ignore in ignores]) if environ.get("TEST_TYPE") == "server":
test_dir = abspath(dirname(__file__))
if secured:
argv.append(join(test_dir, "test_server_secured"))
if sys.version_info >= (3, 6):
argv.append(join(test_dir, "test_async/test_server_secured"))
ignores.extend(
[
"test_opensearchpy/test_server/",
"test_opensearchpy/test_async/test_server/",
]
)
else:
argv.append(join(test_dir, "test_server"))
if sys.version_info >= (3, 6):
argv.append(join(test_dir, "test_async/test_server"))
ignores.extend(
[
"test_opensearchpy/test_server_secured/",
]
)
# Not in CI, run all tests specified. # There are no plugins for unreleased versions of opensearch
else: if environ.get("OPENSEARCH_VERSION") == "SNAPSHOT":
argv.append(abspath(dirname(__file__))) ignores.extend(
[
"test_opensearchpy/test_server/test_plugins/",
"test_opensearchpy/test_async/test_server/test_plugins/",
]
)
if ignores:
argv.extend(["--ignore=%s" % ignore for ignore in ignores])
# Not in CI, run all tests specified.
else:
argv.append(abspath(dirname(__file__)))
exit_code = 0 exit_code = 0
try: try: