Skip to content

DM-55493: Import pytest unconditionally in fastapi_safir_app conftest - #354

Closed
jonathansick wants to merge 1 commit into
mainfrom
tickets/DM-55493b
Closed

jonathansick wants to merge 1 commit into
mainfrom
tickets/DM-55493b

Conversation

@jonathansick

Copy link
Copy Markdown
Member

Summary

In fastapi_safir_app/{{cookiecutter.name}}/tests/conftest.py the pytest
import sits inside a UWS-only Jinja conditional:

{% if cookiecutter.flavor == "UWS" -%}
import pytest
{% endif -%}
import pytest_asyncio

Since 9f67f2b, though, pytest is used in every flavor —
pytest_addoption(parser: pytest.Parser), @pytest.fixture def data(...),
and pytest.FixtureRequest. The committed non-UWS example shows the
result: example/tests/conftest.py calls pytest.Parser and
@pytest.fixture with no import pytest anywhere in the file.

A freshly generated non-UWS app fails at collection:

NameError: name 'pytest' is not defined

This moves the import out of the conditional.

Validation

  • scons re-rendered the examples. The diff is exactly what it should be:
    example/tests/conftest.py gains import pytest, and
    example-uws/tests/conftest.py is unchanged — the UWS rendering
    stays byte-identical.
  • templatekit check (with the two technote.toml ignores CI uses)
    passes: ✅ Passed!

References

Found while scanning template changes for the lsst-sqre maintenance
catalog. Ticket: DM-55493.

Companion PR: #353 fixes the sibling problem in square_pypi_package
(conftest imports safir, but the dev extra doesn't include it). The two
are independent.

The pytest import was inside a UWS-only Jinja conditional, but
pytest_addoption, pytest.FixtureRequest, and the data fixture added in
9f67f2b use pytest in every flavor. A freshly generated non-UWS app
therefore failed at test collection with NameError.

The UWS rendering is unchanged; only the non-UWS example gains the import.
@rra

rra commented Jul 28, 2026

Copy link
Copy Markdown
Member

Just FYI, this is also fixed in #350, which is waiting on a code review. Apologies for missing that; I didn't generate and test a package after making the previous change. (We really should do that as part of the test suite. I keep thinking about it and then not finding the time to do so.)

@jonathansick

Copy link
Copy Markdown
Member Author

My maintenance bot picked these up when I was doing upgrades in my apps, so no worries. I'll close this one and we can just go ahead and merge #350, which is where we want to go anyways.

@jonathansick
jonathansick deleted the tickets/DM-55493b branch August 14, 2026 16:29
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