Skip to content

Commit d036056

Browse files
Raghav-Mah3shwariRaghav
andauthored
KNOX-3394: Correct outdated unittest documentation in Docker Compose integration test README (apache#1324)
Co-authored-by: Raghav <maheshwari@Raghavs-MacBook-Air.local>
1 parent 3c3f3b5 commit d036056

1 file changed

Lines changed: 31 additions & 38 deletions

File tree

.github/workflows/tests/README.md

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This directory contains Python integration tests that run as part of the GitHub
1313
Create a new Python file in this directory (`.github/workflows/tests/`). The filename **must** start with `test_` (e.g., `test_auth.py`) to be automatically discovered by the test runner.
1414

1515
2. **Implement Test Logic**:
16-
Use the `unittest` framework to structure your tests. You can include multiple test methods in a single class, and multiple classes in a single file. Each method starting with `test_` will be executed as a separate test case.
16+
Use `pytest` to structure your tests. Test functions must start with `test_`; test classes must start with `Test` and must not define an `__init__` method. Existing `unittest.TestCase` tests are also supported by pytest.
1717

1818
```python
1919
# Licensed to the Apache Software Foundation (ASF) under one or more
@@ -31,64 +31,57 @@ This directory contains Python integration tests that run as part of the GitHub
3131
# See the License for the specific language governing permissions and
3232
# limitations under the License.
3333

34-
import unittest
35-
import requests
3634
import os
35+
36+
import requests
3737
import urllib3
3838

3939
# Suppress InsecureRequestWarning since we use verify=False for self-signed certs
4040
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
4141

42-
class TestMyFeature(unittest.TestCase):
43-
def setUp(self):
44-
# Get the Knox Gateway URL from environment variables
45-
# Default to localhost for local debugging outside Docker
46-
self.base_url = os.environ.get("KNOX_GATEWAY_URL", "https://localhost:8443/")
47-
48-
def test_my_endpoint(self):
49-
"""
50-
Description of what this test checks.
51-
"""
52-
url = f"{self.base_url}gateway/sandbox/webhdfs/v1/?op=LISTSTATUS"
53-
54-
print(f"Testing URL: {url}")
55-
56-
# Make the request
57-
# verify=False is needed for the dev environment's self-signed certs
58-
response = requests.get(url, verify=False)
59-
60-
# Assertions
61-
self.assertEqual(response.status_code, 200)
62-
# Add more assertions as needed
63-
64-
def test_another_endpoint(self):
65-
"""
66-
Another test case in the same class.
67-
"""
68-
# ... implementation ...
69-
pass
42+
# Default to localhost for local debugging outside Docker.
43+
BASE_URL = os.environ.get("KNOX_GATEWAY_URL", "https://localhost:8443/")
44+
45+
46+
def test_my_endpoint():
47+
"""Verify that the WebHDFS endpoint returns a successful response."""
48+
url = f"{BASE_URL}gateway/sandbox/webhdfs/v1/?op=LISTSTATUS"
49+
50+
# verify=False is needed for the dev environment's self-signed certificate.
51+
response = requests.get(url, verify=False, timeout=30)
52+
53+
assert response.status_code == 200
54+
55+
56+
def test_another_endpoint():
57+
"""Add another independently discovered test."""
58+
response = requests.get(
59+
f"{BASE_URL}gateway/health/v1/ping",
60+
verify=False,
61+
timeout=30,
62+
)
63+
64+
assert response.status_code == 200
7065
```
7166

7267
3. **Add Dependencies**:
7368
If your test requires additional Python libraries (other than `requests`), add them to `requirements.txt` in this directory.
7469

7570
## Organizing Tests in Subdirectories
7671

77-
You can organize tests into subdirectories (e.g., `tests/auth/`, `tests/proxy/`). For the test runner to discover them:
72+
You can organize tests into subdirectories (e.g., `tests/auth/`, `tests/proxy/`). Pytest recursively discovers matching test files:
7873

79-
1. The subdirectory **must** contain an `__init__.py` file (it can be empty).
80-
2. The test files inside must still match the `test_*.py` pattern.
74+
1. Test files must match the `test_*.py` pattern.
75+
2. An `__init__.py` file is optional unless the tests need the directory to be importable as a package.
8176

8277
**Example structure:**
8378

8479
```text
8580
tests/
8681
├── test_health.py
8782
├── auth/
88-
│ ├── __init__.py
8983
│ └── test_auth.py
9084
└── proxy/
91-
├── __init__.py
9285
└── test_proxy.py
9386
```
9487

@@ -98,8 +91,8 @@ The tests run in a dedicated Docker container defined in `../compose/docker-comp
9891

9992
1. The `tests` service mounts this directory (`.github/workflows/tests/`) to `/tests` inside the container.
10093
2. It installs dependencies from `requirements.txt`.
101-
3. It waits for the `knox` service to be ready.
102-
4. It runs `python -m unittest discover -p 'test_*.py'` to find and execute all test files.
94+
3. It waits briefly for the `knox` service to start.
95+
4. It runs `pytest`, excluding the single-EKU suites that are executed separately by the workflow.
10396

10497
## Skipping Tests on Pull Requests
10598

0 commit comments

Comments
 (0)