Skip to content

Commit

Permalink
Add the ability to run test patterns. (#454)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed Jul 26, 2023
1 parent 42852d0 commit e022932
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .ci/functions/imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if [[ -z $opensearch_node_name ]]; then

fi

export script_path=$(dirname $(realpath -s $0))
export script_path=$(dirname $(realpath $0))
source $script_path/functions/cleanup.sh
source $script_path/functions/wait-for-container.sh
trap "cleanup_trap ${network_name}" EXIT
Expand Down
2 changes: 1 addition & 1 deletion .ci/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Bootstrap
# ------------------------------------------------------- #

script_path=$(dirname "$(realpath -s "$0")")
script_path=$(dirname "$(realpath "$0")")
repo=$(realpath "$script_path/../")

# shellcheck disable=SC1090
Expand Down
2 changes: 1 addition & 1 deletion .ci/run-opensearch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# 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
set -euo pipefail

Expand Down
3 changes: 3 additions & 0 deletions .ci/run-repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ docker run \
--env "TEST_SUITE=${TEST_SUITE}" \
--env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \
--env "TEST_TYPE=server" \
--env "TEST_PATTERN=${TEST_PATTERN}" \
--name opensearch-py \
--rm \
opensearch-project/opensearch-py \
python setup.py test

unset TEST_PATTERN
3 changes: 2 additions & 1 deletion .ci/run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=Urllib3HttpConnection
export CLUSTER="${CLUSTER:-opensearch}"
export SECURE_INTEGRATION="${1:-false}"
export OPENSEARCH_VERSION="${2:-latest}"
export TEST_PATTERN="${3:-}"
if [[ "$SECURE_INTEGRATION" == "true" ]]; then
export OPENSEARCH_URL_EXTENSION="https"
else
Expand All @@ -21,7 +22,7 @@ if [[ "$OPENSEARCH_VERSION" == *"SNAPSHOT" ]]; then
fi

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
set -euo pipefail

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
- 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 the ability to run tests matching a pattern to `.ci/run-tests` ([#454](https://github.com/opensearch-project/opensearch-py/pull/454))
### Changed
- Moved security from `plugins` to `clients` ([#442](https://github.com/opensearch-project/opensearch-py/pull/442))
### Deprecated
Expand Down
12 changes: 12 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ $ python --version
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.

```
Expand Down Expand Up @@ -69,6 +71,16 @@ The following example runs tests against the latest SNAPSHOT build of OpenSearch
./.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.

## Linter
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mock
sphinx<7.1
sphinx_rtd_theme
jinja2
pytz

# No wheels for Python 3.10 yet!
numpy; python_version<"3.10"
Expand Down
95 changes: 50 additions & 45 deletions test_opensearchpy/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,58 +111,63 @@ def run_all(argv=None):
if environ.get("OPENSEARCH_URL", "").startswith("https://"):
secured = True

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/",
]
)
# check TEST_PATTERN env var for specific test to run
test_pattern = environ.get("TEST_PATTERN")
if test_pattern:
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/")

# There are no plugins for unreleased versions of opensearch
if environ.get("OPENSEARCH_VERSION") == "SNAPSHOT":
ignores.extend(
[
"test_opensearchpy/test_server/test_plugins/",
"test_opensearchpy/test_async/test_server/test_plugins/",
"test_opensearchpy/test_server/",
"test_opensearchpy/test_server_secured/",
"test_opensearchpy/test_async/test_server/",
"test_opensearchpy/test_async/test_server_secured/",
]
)

if ignores:
argv.extend(["--ignore=%s" % ignore for ignore in ignores])
# 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(
[
"test_opensearchpy/test_server/test_plugins/",
"test_opensearchpy/test_async/test_server/test_plugins/",
]
)

# Not in CI, run all tests specified.
else:
argv.append(abspath(dirname(__file__)))
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
try:
Expand Down

0 comments on commit e022932

Please sign in to comment.