Skip to content

Commit 597448e

Browse files
committed
Remove 'elasticsearch.helpers.test', switch to pytest
1 parent af9515b commit 597448e

30 files changed

+1687
-1987
lines changed

.ci/Dockerfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ ARG PYTHON_VERSION=3.8
22
FROM python:${PYTHON_VERSION}
33

44
WORKDIR /code/elasticsearch-py
5-
COPY dev-requirements.txt .
65
RUN python -m pip install \
76
-U --no-cache-dir \
87
--disable-pip-version-check \
9-
pip \
10-
&& python -m pip install \
11-
--no-cache-dir \
12-
--disable-pip-version-check \
13-
-r dev-requirements.txt
8+
nox
149

1510
COPY . .
1611
RUN python -m pip install -e .

.ci/run-nox.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
if [[ -z "$NOX_SESSION" ]]; then
4+
NOX_SESSION=test-${PYTHON_VERSION%-dev}
5+
fi
6+
nox -s $NOX_SESSION

.ci/run-repository.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ docker run \
4242
--name elasticsearch-py \
4343
--rm \
4444
elastic/elasticsearch-py \
45-
python setup.py test
45+
nox -s test

.ci/test-matrix.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ TEST_SUITE:
55
- platinum
66

77
PYTHON_VERSION:
8-
- "2.7"
9-
- "3.4"
10-
- "3.5"
118
- "3.6"
129
- "3.7"
1310
- "3.8"

.github/workflows/ci.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
steps:
1010
- name: Checkout Repository
1111
uses: actions/checkout@v1
12-
- name: Set up Python 3.7
12+
- name: Set up Python 3.x
1313
uses: actions/setup-python@v2
1414
with:
15-
python-version: 3.7
15+
python-version: 3.x
1616
- name: Install dependencies
1717
run: |
18-
python3.7 -m pip install nox
18+
python3 -m pip install nox
1919
- name: Lint the code
2020
run: nox -s lint
2121

@@ -27,22 +27,24 @@ jobs:
2727
- name: Set up Python 3.7
2828
uses: actions/setup-python@v2
2929
with:
30-
python-version: 3.7
30+
python-version: 3.x
3131
- name: Install dependencies
3232
run: |
33-
python3.7 -m pip install nox
33+
python3 -m pip install nox
3434
- name: Build the docs
3535
run: nox -s docs
3636

3737
test-linux:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9]
41+
python-version: [3.6, 3.7, 3.8, 3.9]
4242
experimental: [false]
43+
nox-session: [""]
4344
include:
4445
- python-version: 3.10-dev
4546
experimental: true
47+
nox-session: "3.10"
4648

4749
runs-on: ubuntu-latest
4850
name: test-${{ matrix.python-version }}
@@ -56,7 +58,10 @@ jobs:
5658
python-version: ${{ matrix.python-version }}
5759
- name: Install Dependencies
5860
run: |
59-
python -m pip install -r dev-requirements.txt
61+
python -m pip install nox
6062
- name: Run Tests
61-
run: |
62-
python setup.py test
63+
shell: bash
64+
run: .ci/run-nox.sh
65+
env:
66+
PYTHON_VERSION: ${{ matrix.python-version }}
67+
NOX_SESSION: ${{ matrix.nox-session }}

elasticsearch/helpers/test.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

noxfile.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
import os
19+
1820
import nox
1921

22+
SOURCE_DIR = os.path.dirname(os.path.abspath(__file__))
2023
SOURCE_FILES = (
2124
"setup.py",
2225
"noxfile.py",
@@ -26,12 +29,26 @@
2629
)
2730

2831

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

34-
session.run("python", "setup.py", "test")
37+
python_version = tuple(int(x) for x in session.python.split("."))
38+
junit_xml = os.path.join(SOURCE_DIR, "junit", "elasticsearch-py-junit.xml")
39+
pytest_argv = [
40+
"pytest",
41+
"--cov=elasticsearch",
42+
"--junitxml=%s" % junit_xml,
43+
"--log-level=DEBUG",
44+
"--cache-clear",
45+
"-vv",
46+
]
47+
# Python 3.6+ is required for async
48+
if python_version < (3, 6):
49+
pytest_argv.append("--ignore=test_elasticsearch/test_async/")
50+
51+
session.run(*pytest_argv)
3552

3653

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

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

6077
# Run mypy on the package and then the type examples separately for
6178
# the two different mypy use-cases, ourselves and our users.

setup.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,7 @@
5555
"urllib3>=1.21.1, <2",
5656
"certifi",
5757
]
58-
tests_require = [
59-
"requests>=2.0.0, <3.0.0",
60-
"coverage",
61-
"mock",
62-
"pyyaml",
63-
"pytest",
64-
"pytest-cov",
65-
]
66-
async_require = ["aiohttp>=3,<4"]
67-
68-
docs_require = ["sphinx<1.7", "sphinx_rtd_theme"]
69-
generate_require = ["black", "jinja2"]
58+
async_requires = ["aiohttp>=3,<4"]
7059

7160
setup(
7261
name=package_name,
@@ -109,12 +98,8 @@
10998
],
11099
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4",
111100
install_requires=install_requires,
112-
test_suite="test_elasticsearch.run_tests.run_all",
113-
tests_require=tests_require,
114101
extras_require={
115-
"develop": tests_require + docs_require + generate_require,
116-
"docs": docs_require,
117102
"requests": ["requests>=2.4.0, <3.0.0"],
118-
"async": async_require,
103+
"async": async_requires,
119104
},
120105
)

elasticsearch/helpers/test.pyi renamed to test_elasticsearch/conftest.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from typing import Any, Tuple
19-
from unittest import TestCase
18+
from typing import Tuple
2019

21-
from ..client import Elasticsearch
20+
import pytest
2221

23-
ELASTICSEARCH_URL: str
24-
CA_CERTS: str
22+
from elasticsearch import Elasticsearch
2523

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

29-
class ElasticsearchTestCase(TestCase):
30-
@staticmethod
31-
def _get_client() -> Elasticsearch: ...
32-
@classmethod
33-
def setup_class(cls) -> None: ...
34-
def teardown_method(self, _: Any) -> None: ...
35-
def es_version(self) -> Tuple[int, ...]: ...
26+
27+
@pytest.fixture(scope="session")
28+
def elasticsearch_url():
29+
try:
30+
return es_url()
31+
except RuntimeError as e:
32+
pytest.skip(str(e))
33+
34+
35+
@pytest.fixture(scope="session")
36+
def elasticsearch_version(elasticsearch_url) -> Tuple[int, ...]:
37+
"""Returns the version of the current Elasticsearch cluster"""
38+
return es_version(Elasticsearch(elasticsearch_url, ca_certs=CA_CERTS))

0 commit comments

Comments
 (0)