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:
- Python 3.8
- Python 3.9
- Python 3.10
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 same tutorial010, we have these variants:
docs_src/query_params_str_validations/tutorial010_an_py39.py
- Using
Annotated, Python 3.9.
docs_src/query_params_str_validations/tutorial010_an_py310.py
- Using
Annotated, Python 3.10.
docs_src/query_params_str_validations/tutorial010_an.py
- Using
Annotated, Python 3.8 (as 3.8 is the oldest, this one doesn't have a part in the name like py38).
docs_src/query_params_str_validations/tutorial010_py310.py
- Python 3.10, not using
Annotated (as not using Annotated is the oldest form, it just doesn't have the an part in the file name.
docs_src/query_params_str_validations/tutorial010.py
- Not using
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.
- 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
- Copy the changes visible from the file in https://github.com/fastapi/fastapi/pull/13149/files, mainly:
- The
params= part
- The
request: pytest.FixtureRequest param
- The mod = importlib.import_module(` part
- 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.
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
Annotatedand 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.pyAnnotated, Python 3.9.docs_src/query_params_str_validations/tutorial010_an_py310.pyAnnotated, Python 3.10.docs_src/query_params_str_validations/tutorial010_an.pyAnnotated, 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.pyAnnotated(as not usingAnnotatedis the oldest form, it just doesn't have theanpart in the file name.docs_src/query_params_str_validations/tutorial010.pyAnnotated, 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.pytests/test_tutorial/test_query_params_str_validations/test_tutorial010_an_py310.pytests/test_tutorial/test_query_params_str_validations/test_tutorial010_an.pytests/test_tutorial/test_query_params_str_validations/test_tutorial010_py310.pytests/test_tutorial/test_query_params_str_validations/test_tutorial010.pyBut 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 extraxat the end:docs_src/query_params_str_validations/tutorial010x.pyparams=partrequest: pytest.FixtureRequestparamTestClient(mod.app)with the newmod.appFor 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
xat the end.