You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each of these files represent the same FastAPI app, but with the improved syntax for Python 3.9, or 3.10, or using Annotated, but in the end, the same app.
We want to keep these files like this because they have the different ways to create an app, the different supported syntaxes, including backward-compatible ones. They are shown in the docs and tested on CI.
Then, we have tests for that... currently, we just have a test file per variant file, so, we have:
But then, each of the files is almost exactly the same code, only with Pytest "markers" to define that something should only be run on Python 3.10, etc. but apart from that, they have the same code.
The Task
The task is to replace the multiple test files for each variant with a single file that uses Pytest parameters to import each specific app, and that uses Pytest markers for the files that require a specific version of Python.
An example of the result for one of these test variants is here: #13149
Not all tutorial tests have multiple variants, but there are a few that do. This can be done in one PR per tutorial (with the single test for all its variants).
Instructions
These are not strict but they worked for me to simplify the process.
Take one of the tests that requires a Python version, say Python 3.10, e.g. docs_src/query_params_str_validations/tutorial010_an_py310.py, copy it to a new file with a different name (only temporarily), e.g. with an extra x at the end: docs_src/query_params_str_validations/tutorial010x.py
The client = TestClient(mod.app) with the new mod.app
For that tutorial, e.g. tutorial010, there are a few variants, in this case, 5. There should be one param for each of those 5 files.
The ones with a name with a variant part for Python 3.10 (py310) should have marks=needs_py310, and the ones for Python 3.9 (py39) should have marks=needs_py39.
Once that is done and the tests in that file are passing, remove the other files, and rename that test to remove the extra x at the end.
The text was updated successfully, but these errors were encountered:
Privileged issue
Issue Content
Summary
Simplify tests for variants, from multiple test files (one test file per variant) to a single test file with parameters to test each variant.
Background
Currently, we have multiple source example variants for different Python versions:
And we have versions using
Annotated
and without using it.Combining that, for each source app, we end up with different variants.
For example, for
docs_src/query_params_str_validations/tutorial010.py
, for this sametutorial010
, we have these variants:docs_src/query_params_str_validations/tutorial010_an_py39.py
Annotated
, Python 3.9.docs_src/query_params_str_validations/tutorial010_an_py310.py
Annotated
, Python 3.10.docs_src/query_params_str_validations/tutorial010_an.py
Annotated
, Python 3.8 (as 3.8 is the oldest, this one doesn't have a part in the name likepy38
).docs_src/query_params_str_validations/tutorial010_py310.py
Annotated
(as not usingAnnotated
is the oldest form, it just doesn't have thean
part in the file name.docs_src/query_params_str_validations/tutorial010.py
Annotated
, Python 3.8.Each of these files represent the same FastAPI app, but with the improved syntax for Python 3.9, or 3.10, or using
Annotated
, but in the end, the same app.We want to keep these files like this because they have the different ways to create an app, the different supported syntaxes, including backward-compatible ones. They are shown in the docs and tested on CI.
Then, we have tests for that... currently, we just have a test file per variant file, so, we have:
tests/test_tutorial/test_query_params_str_validations/test_tutorial010_an_py39.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010_an_py310.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010_an.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010_py310.py
tests/test_tutorial/test_query_params_str_validations/test_tutorial010.py
But then, each of the files is almost exactly the same code, only with Pytest "markers" to define that something should only be run on Python 3.10, etc. but apart from that, they have the same code.
The Task
The task is to replace the multiple test files for each variant with a single file that uses Pytest parameters to import each specific app, and that uses Pytest markers for the files that require a specific version of Python.
An example of the result for one of these test variants is here: #13149
Not all tutorial tests have multiple variants, but there are a few that do. This can be done in one PR per tutorial (with the single test for all its variants).
Instructions
These are not strict but they worked for me to simplify the process.
docs_src/query_params_str_validations/tutorial010_an_py310.py
, copy it to a new file with a different name (only temporarily), e.g. with an extrax
at the end:docs_src/query_params_str_validations/tutorial010x.py
params=
partrequest: pytest.FixtureRequest
paramTestClient(mod.app)
with the newmod.app
For that tutorial, e.g. tutorial010, there are a few variants, in this case, 5. There should be one param for each of those 5 files.
The ones with a name with a variant part for Python 3.10 (
py310
) should havemarks=needs_py310
, and the ones for Python 3.9 (py39
) should havemarks=needs_py39
.Once that is done and the tests in that file are passing, remove the other files, and rename that test to remove the extra
x
at the end.The text was updated successfully, but these errors were encountered: