Skip to content

Fix URL normalization and fixture yield consistency in all integrity tests#47

Merged
ondratu merged 3 commits intomasterfrom
copilot/fix-url-normalization-in-test
May 2, 2026
Merged

Fix URL normalization and fixture yield consistency in all integrity tests#47
ondratu merged 3 commits intomasterfrom
copilot/fix-url-normalization-in-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

The server fixture in multiple integrity test files had two issues: strip('/') was stripping leading slashes from URLs (wrong for a base URL), and the fixture mixed return with yield, making teardown unreachable in the early-exit branch.

Changes

  • striprstrip: Only trailing slashes are removed from the environment-supplied URL, preserving any leading slashes.
  • Consistent yield in both branches: Replaced return val with yield val inside an if/else block so pytest teardown always runs. Process teardown is guarded with if process is not None: to safely handle the no-server branch.
  • Removed now-redundant # pylint: disable=inconsistent-return-statements from all affected files.
# Before
val = environ.get("TEST_URL", "").strip('/')
if val:
    return val          # teardown never runs; also strips leading slashes
yield "http://localhost:8080"
process.kill()

# After
process = None
val = environ.get("TEST_URL", "").rstrip('/')
if val:
    yield val
else:
    process = start_server(...)
    yield "http://localhost:8080"
if process is not None:
    process.kill()
    process.wait()

Affected files

  • tests_integrity/test_aes_session.py
  • tests_integrity/test_digest.py
  • tests_integrity/test_session.py
  • tests_integrity/test_websocket.py
  • tests_integrity/test_profile.py
  • tests_integrity/test_json.py
  • tests_integrity/test_simple.py
  • tests_integrity/test_openapi.py
  • tests_integrity/test_metrics.py
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The `strip('/')` call removes all leading and trailing slashes from the URL, which could produce unexpected results if the URL has multiple trailing slashes or if the URL is just '/'. Consider using `rstrip('/')` instead to only remove trailing slashes, which is more aligned with typical URL normalization.","fixFiles":[{"filePath":"tests_integrity/test_aes_session.py","diff":"diff --git a/tests_integrity/test_aes_session.py b/tests_integrity/test_aes_session.py\n--- a/tests_integrity/test_aes_session.py\n+++ b/tests_integrity/test_aes_session.py\n@@ -16,7 +16,7 @@\n @fixture(scope=\"module\")\n def url(request):\n     \"\"\"The URL (server fixture).\"\"\"\n-    val = environ.get(\"TEST_AES_SESSION_URL\", \"\").strip('/')\n+    val = environ.get(\"TEST_AES_SESSION_URL\", \"\").rstrip('/')\n     if val:\n         return val\n \n"}]},{"message":"The fixture does not return the process in the if-branch (lines 19-21), but yields it in the else-branch (lines 27-29). This inconsistency could lead to confusion. Consider restructuring the fixture so both branches return or yield consistently, or document why the behavior differs.","fixFiles":[{"filePath":"tests_integrity/test_aes_session.py","diff":"diff --git a/tests_integrity/test_aes_session.py b/tests_integrity/test_aes_session.py\n--- a/tests_integrity/test_aes_session.py\n+++ b/tests_integrity/test_aes_session.py\n@@ -16,19 +16,21 @@\n @fixture(scope=\"module\")\n def url(request):\n     \"\"\"The URL (server fixture).\"\"\"\n+    process = None\n     val = environ.get(\"TEST_AES_SESSION_URL\", \"\").strip('/')\n     if val:\n-        return val\n+        yield val\n+    else:\n+        process = start_server(\n+            request,\n+            join(dirname(__file__), pardir, 'examples/aes_session.py'))\n+        yield \"http://localhost:8080\"  # server is running\n \n-    process = start_server(\n-        request,\n-        join(dirname(__file__), pardir, 'examples/aes_session.py'))\n+    if process is not None:\n+        process.kill()\n+        process.wait()\n \n-    yield \"http://localhost:8080\"  # server is running\n-    process.kill()\n-    process.wait()\n \n-\n @fixture\n def logged_in(url):\n     \"\"\"Fixture that logs in with valid credentials and returns the session.\"\"\"\n"}]}]

Copilot AI changed the title [WIP] Fix URL normalization by using rstrip instead of strip Fix URL normalization and fixture yield consistency in test_aes_session May 2, 2026
Copilot finished work on behalf of ondratu May 2, 2026 07:50
Copilot AI requested a review from ondratu May 2, 2026 07:50
@ondratu
Copy link
Copy Markdown
Contributor

ondratu commented May 2, 2026

@copilot fix all integrity tests with the same approach

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 2, 2026

@copilot fix all integrity tests with the same approach

Done in e89a184. Applied the same approach to all remaining integrity tests:

  • strip('/')rstrip('/') on every env-var URL read
  • return val replaced with yield val inside an if/else block so both branches yield consistently
  • if process is not None: teardown guard on all fixtures
  • # pylint: disable=inconsistent-return-statements removed from all files

Files updated: test_digest.py, test_session.py, test_websocket.py, test_profile.py, test_json.py, test_simple.py, test_openapi.py, test_metrics.py.

Copilot AI changed the title Fix URL normalization and fixture yield consistency in test_aes_session Fix URL normalization and fixture yield consistency in all integrity tests May 2, 2026
Copilot finished work on behalf of ondratu May 2, 2026 07:59
@ondratu ondratu marked this pull request as ready for review May 2, 2026 08:05
@ondratu ondratu merged commit d9bbaf5 into master May 2, 2026
7 checks passed
@ondratu ondratu deleted the copilot/fix-url-normalization-in-test branch May 2, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants