Skip to content

Build test URLs with f-strings instead of string concatenation #644

Description

@nanotaboada

Problem

tests/test_main.py builds request paths by concatenating fragments:

response = client.get(PATH + "squadnumber" + "/" + str(squad_number))
response = client.put(PATH + "squadnumber/" + str(squad_number), json=...)

The file already uses f-strings elsewhere
(f"/players/squadnumber/{player.squad_number}"), so the style is
inconsistent. The + "/" + str(...) form is noisy and fragile — the first
example only produces a valid URL because PATH happens to end in /.

Proposed Solution

Use f-strings consistently, and lift the repeated literal into a constant next
to the existing PATH:

PATH = "/players/"
SQUAD_PATH = "/players/squadnumber"
# ...
response = client.get(f"{SQUAD_PATH}/{squad_number}")

Suggested Approach

  1. Add SQUAD_PATH beside PATH.
  2. Replace every PATH + ... + str(...) with an f-string.
  3. No behavioural change — the generated URLs must be identical. Run
    uv run pytest.
  4. tests/test_main.py is excluded from Black — keep the manual formatting
    style.

Acceptance Criteria

  • No +-based URL building remains in tests/test_main.py
  • Generated URLs are unchanged
  • All tests pass
  • CHANGELOG.md updated

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority:lowNice-to-have improvement. Can be deferred without blocking other work.pythonPull requests that update Python codepython:idiomsRefactors toward idiomatic Python (PEP conventions, stdlib idioms)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions