Skip to content

Remove 'elasticsearch.helpers.test', switch to pytest #1692

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

Merged
merged 1 commit into from
Aug 25, 2021
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
6 changes: 1 addition & 5 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ COPY dev-requirements.txt .
RUN python -m pip install \
-U --no-cache-dir \
--disable-pip-version-check \
pip \
&& python -m pip install \
--no-cache-dir \
--disable-pip-version-check \
-r dev-requirements.txt
nox -rdev-requirements.txt

COPY . .
RUN python -m pip install -e .
6 changes: 6 additions & 0 deletions .ci/run-nox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

if [[ -z "$NOX_SESSION" ]]; then
NOX_SESSION=test-${PYTHON_VERSION%-dev}
fi
nox -s $NOX_SESSION
2 changes: 1 addition & 1 deletion .ci/run-repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ docker run \
--name elasticsearch-py \
--rm \
elastic/elasticsearch-py \
python setup.py test
nox -s test
3 changes: 0 additions & 3 deletions .ci/test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ TEST_SUITE:
- platinum

PYTHON_VERSION:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
Expand Down
23 changes: 14 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v1
- name: Set up Python 3.7
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.x
- name: Install dependencies
run: |
python3.7 -m pip install nox
python3 -m pip install nox
- name: Lint the code
run: nox -s lint

Expand All @@ -27,22 +27,24 @@ jobs:
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.x
- name: Install dependencies
run: |
python3.7 -m pip install nox
python3 -m pip install nox
- name: Build the docs
run: nox -s docs

test-linux:
strategy:
fail-fast: false
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
python-version: [3.6, 3.7, 3.8, 3.9]
experimental: [false]
nox-session: [""]
include:
- python-version: 3.10-dev
experimental: true
nox-session: test-3.10

runs-on: ubuntu-latest
name: test-${{ matrix.python-version }}
Expand All @@ -56,7 +58,10 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install -r dev-requirements.txt
python -m pip install nox
- name: Run Tests
run: |
python setup.py test
shell: bash
run: .ci/run-nox.sh
env:
PYTHON_VERSION: ${{ matrix.python-version }}
NOX_SESSION: ${{ matrix.nox-session }}
99 changes: 0 additions & 99 deletions elasticsearch/helpers/test.py

This file was deleted.

23 changes: 20 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
# specific language governing permissions and limitations
# under the License.

import os

import nox

SOURCE_DIR = os.path.dirname(os.path.abspath(__file__))
SOURCE_FILES = (
"setup.py",
"noxfile.py",
Expand All @@ -26,12 +29,26 @@
)


@nox.session(python=["2.7", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9"])
@nox.session(python=["2.7", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10"])
def test(session):
session.install(".")
session.install("-r", "dev-requirements.txt")

session.run("python", "setup.py", "test")
python_version = tuple(int(x) for x in session.python.split("."))
junit_xml = os.path.join(SOURCE_DIR, "junit", "elasticsearch-py-junit.xml")
pytest_argv = [
"pytest",
"--cov=elasticsearch",
"--junitxml=%s" % junit_xml,
"--log-level=DEBUG",
"--cache-clear",
"-vv",
]
# Python 3.6+ is required for async
if python_version < (3, 6):
pytest_argv.append("--ignore=test_elasticsearch/test_async/")

session.run(*pytest_argv)


@nox.session()
Expand All @@ -55,7 +72,7 @@ def lint(session):
session.run("python", "utils/license-headers.py", "check", *SOURCE_FILES)

# Workaround to make '-r' to still work despite uninstalling aiohttp below.
session.run("python", "-m", "pip", "install", "aiohttp")
session.install("aiohttp")

# Run mypy on the package and then the type examples separately for
# the two different mypy use-cases, ourselves and our users.
Expand Down
19 changes: 2 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,7 @@
"urllib3>=1.21.1, <2",
"certifi",
]
tests_require = [
"requests>=2.0.0, <3.0.0",
"coverage",
"mock",
"pyyaml",
"pytest",
"pytest-cov",
]
async_require = ["aiohttp>=3,<4"]

docs_require = ["sphinx<1.7", "sphinx_rtd_theme"]
generate_require = ["black", "jinja2"]
async_requires = ["aiohttp>=3,<4"]

setup(
name=package_name,
Expand Down Expand Up @@ -109,12 +98,8 @@
],
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4",
install_requires=install_requires,
test_suite="test_elasticsearch.run_tests.run_all",
tests_require=tests_require,
extras_require={
"develop": tests_require + docs_require + generate_require,
"docs": docs_require,
"requests": ["requests>=2.4.0, <3.0.0"],
"async": async_require,
"async": async_requires,
},
)
31 changes: 17 additions & 14 deletions elasticsearch/helpers/test.pyi → test_elasticsearch/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@
# specific language governing permissions and limitations
# under the License.

from typing import Any, Tuple
from unittest import TestCase
from typing import Tuple

from ..client import Elasticsearch
import pytest

ELASTICSEARCH_URL: str
CA_CERTS: str
from elasticsearch import Elasticsearch

def get_test_client(nowait: bool = ..., **kwargs: Any) -> Elasticsearch: ...
def _get_version(version_string: str) -> Tuple[int, ...]: ...
from .utils import CA_CERTS, es_url, es_version

class ElasticsearchTestCase(TestCase):
@staticmethod
def _get_client() -> Elasticsearch: ...
@classmethod
def setup_class(cls) -> None: ...
def teardown_method(self, _: Any) -> None: ...
def es_version(self) -> Tuple[int, ...]: ...

@pytest.fixture(scope="session")
def elasticsearch_url():
try:
return es_url()
except RuntimeError as e:
pytest.skip(str(e))


@pytest.fixture(scope="session")
def elasticsearch_version(elasticsearch_url) -> Tuple[int, ...]:
"""Returns the version of the current Elasticsearch cluster"""
return es_version(Elasticsearch(elasticsearch_url, ca_certs=CA_CERTS))
Loading