doc: Include pytests directly in documentation
RFC PATCH 1/1 doc: Include pytests directly in documentation
As there is support within the Sphinx framework to take Python docstrings and generate documentation from it, we can make use of that to more clearly and consistently document our pytests and how to configure them. To do this we:
- Add PYTHONPATH to DOC_TARGETS so that modules will be found, have CI install pytest module as well.
- Add the autodoc extension for Python and then redirects so we can move py_testing.html (which is heavily referenced in archives, etc).
- Create a doc/develop/pytest directory and move the existing py_testing file there, update references.
- Update the test_000_version.py test to have a docstring
- Move the imports in test_net_boot.py so the docstring is in the correct place.
- Use code-block for all of the code blocks in test_net_boot.py so they are rendered correctly in documentation.
- Adding these code-block lines makes the diff larger when read but a "git show -w" for example makes it clearer that the textual changes are removing '#' from lines so the output reads nicer.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
As this is a RFC, I didn't split it up as much as it needs to be as I'm looking for some feedback on the concept.
---
.azure-pipelines.yml | 2 +-
.gitlab-ci.yml | 2 +-
Makefile | 3 +-
doc/conf.py | 8 +-
doc/develop/ci_testing.rst | 2 +-
doc/develop/index.rst | 2 +-
doc/develop/pytest/index.rst | 21 +++
doc/develop/pytest/test_000_version.rst | 8 +
doc/develop/pytest/test_net_boot.rst | 8 +
.../{py_testing.rst => pytest/usage.rst} | 2 +-
doc/develop/testing.rst | 4 +-
doc/develop/tests_writing.rst | 2 +-
doc/sphinx/requirements.txt | 1 +
test/py/tests/test_000_version.py | 10 +-
test/py/tests/test_net_boot.py | 163 ++++++++++--------
15 files changed, 150 insertions(+), 88 deletions(-)
create mode 100644 doc/develop/pytest/index.rst
create mode 100644 doc/develop/pytest/test_000_version.rst
create mode 100644 doc/develop/pytest/test_net_boot.rst
rename doc/develop/{py_testing.rst => pytest/usage.rst} (99%).azure-pipelines.yml +1 -1
@@ -92,7 +92,7 @@ stages: set -e virtualenv -p /usr/bin/python3 /tmp/venvhtml . /tmp/venvhtml/bin/activate - pip install -r doc/sphinx/requirements.txt + pip install -r doc/sphinx/requirements.txt pytest make htmldocs KDOC_WERROR=1 make infodocs
.gitlab-ci.yml +1 -1
@@ -156,7 +156,7 @@ docs: script: - virtualenv -p /usr/bin/python3 /tmp/venvhtml - . /tmp/venvhtml/bin/activate - - pip install -r doc/sphinx/requirements.txt + - pip install -r doc/sphinx/requirements.txt pytest - make htmldocs KDOC_WERROR=1 - make infodocs
Makefile +2 -1
@@ -2445,7 +2445,8 @@ DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs texinfodocs infodocs PHONY += $(DOC_TARGETS) $(DOC_TARGETS): scripts_basic FORCE - $(Q)$(MAKE) $(build)=doc $@ + $(Q)PYTHONPATH=$(srctree)/test/py/tests:$(srctree)/test/py \ + $(MAKE) $(build)=doc $@ PHONY += checkstack ubootrelease ubootversion
doc/conf.py +7 -1
@@ -47,7 +47,8 @@ needs_sphinx = '2.4.4' extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'kfigure', 'sphinx.ext.ifconfig', # 'automarkup', 'maintainers_include', 'sphinx.ext.autosectionlabel', - 'kernel_abi', 'kernel_feat', 'sphinx-prompt'] + 'kernel_abi', 'kernel_feat', 'sphinx-prompt', + 'sphinx.ext.autodoc', 'sphinx_reredirects' ] # # cdomain is badly broken in Sphinx 3+. Leaving it out generates *most*
@@ -148,6 +149,11 @@ project = 'Das U-Boot' copyright = 'The U-Boot development community' author = 'The U-Boot development community' +# Pages we have moved after being heavily referenced externally +redirects = { + "develop/py_testing": "pytest/usage.html" +} + # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents.
doc/develop/ci_testing.rst +1 -1
@@ -18,7 +18,7 @@ be built with mingw to run on Windows. Each of the pipelines is written in such as way as to be a "world build" style test and as such we try and build all possible platforms. In addition, for all platforms that support being run in QEMU we run them in QEMU and use our pytest -suite. See :doc:`py_testing` for more information about those tests. +suite. See :doc:`pytest/usage` for more information about those tests. Azure Pipelines ---------------
doc/develop/index.rst +1 -1
@@ -81,7 +81,7 @@ Testing :maxdepth: 1 testing - py_testing + pytest/index tests_writing tests_sandbox binman_tests
doc/develop/pytest/index.rst new file +21 -0
@@ -0,0 +1,21 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +pytest Framework within U-Boot +============================== + +General +------- + +.. toctree:: + :maxdepth: 1 + + usage + +Individual tests +---------------- + +.. toctree:: + :maxdepth: 1 + + test_000_version + test_net_boot
doc/develop/pytest/test_000_version.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_000_version +================ + +.. automodule:: test_000_version + :synopsis: + :member-order: bysource + :members: + :undoc-members:
doc/develop/pytest/test_net_boot.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_net_boot +============= + +.. automodule:: test_net_boot + :synopsis: + :member-order: bysource + :members: + :undoc-members:
doc/develop/pytest/usage.rst renamed from doc/develop/py_testing.rst +1 -1
@@ -13,7 +13,7 @@ results. Advantages of this approach are: U-Boot; there can be no disconnect. - There is no need to write or embed test-related code into U-Boot itself. It is asserted that writing test-related code in Python is simpler and more - flexible than writing it all in C. But see :doc:`tests_writing` for caveats + flexible than writing it all in C. But see :doc:`../tests_writing` for caveats and more discussion / analysis. - It is reasonably simple to interact with U-Boot in this way.
doc/develop/testing.rst +2 -2
@@ -33,7 +33,7 @@ You can also run a selection tests in parallel with:: make pcheck All of the above use the test/run script with a paremeter to select which tests -are run. See :doc:`py_testing` for more information. +are run. See :doc:`pytest/usage` for more information. Sandbox
@@ -69,7 +69,7 @@ build:: ./test/py/test.py --bd sandbox_spl --build -k test_spl -See :doc:`py_testing` for more information about the pytest suite. +See :doc:`pytest/usage` for more information about the pytest suite. See :doc:`tests_sandbox` for how to run tests directly (not through pytest).
doc/develop/tests_writing.rst +1 -1
@@ -376,5 +376,5 @@ An example SPL test is spl_test_load(). Writing Python tests -------------------- -See :doc:`py_testing` for brief notes how to write Python tests. You +See :doc:`pytest/usage` for brief notes how to write Python tests. You should be able to use the existing tests in test/py/tests as examples.
doc/sphinx/requirements.txt +1 -0
@@ -15,6 +15,7 @@ six==1.16.0 snowballstemmer==2.2.0 Sphinx==8.1.3 sphinx-prompt==1.9.0 +sphinx-reredirects==0.1.5 sphinx-rtd-theme==3.0.1 sphinxcontrib-applehelp==2.0.0 sphinxcontrib-devhelp==2.0.0
test/py/tests/test_000_version.py +6 -4
@@ -2,10 +2,12 @@ # Copyright (c) 2015 Stephen Warren # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. -# pytest runs tests the order of their module path, which is related to the -# filename containing the test. This file is named such that it is sorted -# first, simply as a very basic sanity check of the functionality of the U-Boot -# command prompt. +""" +pytest runs tests the order of their module path, which is related to the +filename containing the test. This file is named such that it is sorted +first, simply as a very basic sanity check of the functionality of the U-Boot +command prompt. +""" def test_version(u_boot_console): """Test that the "version" command prints the U-Boot version."""
test/py/tests/test_net_boot.py +89 -74
195 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 19 lines · Tom Rini
As there is support within the Sphinx framework to take Python docstrings and generate documentation from it, we can make use of that to more clearly and consistently document our pytests and how to configure them. To do this we:
- Add PYTHONPATH toDOC_TARGETSso that modules will be found, have CI install pytest module as well.
- Add the autodoc extension for Python and then redirects so we can move py_testing.html (which is heavily referenced in archives, etc).
- Create a doc/develop/pytest directory and move the existingpy_testingfile there, update references.
- Update thetest_000_version.pytest to have a docstring
- Move the imports intest_net_boot.pyso the docstring is in the correct place.
- Use code-block for all of the code blocks intest_net_boot.pyso they are rendered correctly in documentation.
- Adding these code-block lines makes the diff larger when read but a "git show -w" for example makes it clearer that the textual changes are removing '#' from lines so the output reads nicer.
Quoted 1 line
Signed-off-by Tom Rini <[email protected]>
Some of the test functions seem to lack documentation:
test_net_boot.setup_networking()test_net_boot.setup_tftpboot_boot()
Would you know what 000 in the following filename corresponds to?
test/py/tests/test_000_version.py
Maybe we should rename to test_version.py it before adding this patch.
Quoted 461 lines
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>As this is a RFC, I didn't split it up as much as it needs to be as I'm looking for some feedback on the concept.
--- .azure-pipelines.yml | 2 +- .gitlab-ci.yml | 2 +- Makefile | 3 +- doc/conf.py | 8 +- doc/develop/ci_testing.rst | 2 +- doc/develop/index.rst | 2 +- doc/develop/pytest/index.rst | 21 +++ doc/develop/pytest/test_000_version.rst | 8 + doc/develop/pytest/test_net_boot.rst | 8 + .../{py_testing.rst => pytest/usage.rst} | 2 +- doc/develop/testing.rst | 4 +- doc/develop/tests_writing.rst | 2 +- doc/sphinx/requirements.txt | 1 + test/py/tests/test_000_version.py | 10 +- test/py/tests/test_net_boot.py | 163 ++++++++++-------- 15 files changed, 150 insertions(+), 88 deletions(-)create mode 100644
doc/develop/pytest/index.rstcreate mode 100644doc/develop/pytest/test_000_version.rstcreate mode 100644doc/develop/pytest/test_net_boot.rstrenamedoc/develop/{py_testing.rst=>pytest/usage.rst} (99%).azure-pipelines.yml +1
-1@@ -92,7 +92,7 @@ stages: set -e virtualenv -p /usr/bin/python3 /tmp/venvhtml . /tmp/venvhtml/bin/activate - pip install -r doc/sphinx/requirements.txt + pip install -r doc/sphinx/requirements.txt pytest make htmldocs KDOC_WERROR=1 make infodocs.gitlab-ci.yml +1
-1@@ -156,7 +156,7 @@ docs: script: - virtualenv -p /usr/bin/python3 /tmp/venvhtml - . /tmp/venvhtml/bin/activate - - pip install -r doc/sphinx/requirements.txt + - pip install -r doc/sphinx/requirements.txt pytest - make htmldocs KDOC_WERROR=1 - make infodocsMakefile +2
-1@@ -2445,7 +2445,8 @@ DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs texinfodocs infodocs PHONY += $(DOC_TARGETS) $(DOC_TARGETS): scripts_basic FORCE - $(Q)$(MAKE) $(build)=doc $@ + $(Q)PYTHONPATH=$(srctree)/test/py/tests:$(srctree)/test/py \ + $(MAKE) $(build)=doc $@ PHONY += checkstack ubootrelease ubootversiondoc/conf.py +7
-1@@ -47,7 +47,8 @@ needs_sphinx = '2.4.4' extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'kfigure', 'sphinx.ext.ifconfig', # 'automarkup', 'maintainers_include', 'sphinx.ext.autosectionlabel', - 'kernel_abi', 'kernel_feat', 'sphinx-prompt'] + 'kernel_abi', 'kernel_feat', 'sphinx-prompt', + 'sphinx.ext.autodoc', 'sphinx_reredirects' ] # # cdomain is badly broken in Sphinx 3+. Leaving it out generates *most*@@ -148,6 +149,11 @@ project = 'Das U-Boot' copyright = 'The U-Boot development community' author = 'The U-Boot development community' +# Pages we have moved after being heavily referenced externally +redirects = { + "develop/py_testing": "pytest/usage.html" +} + # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents.doc/develop/ci_testing.rst +1
-1@@ -18,7 +18,7 @@ be built with mingw to run on Windows. Each of the pipelines is written in such as way as to be a "world build" style test and as such we try and build all possible platforms. In addition, for all platforms that support being run in QEMU we run them in QEMU and use our pytest -suite. See :doc:`py_testing` for more information about those tests. +suite. See :doc:`pytest/usage` for more information about those tests. Azure Pipelines ---------------doc/develop/index.rst +1
-1@@ -81,7 +81,7 @@ Testing :maxdepth: 1 testing - py_testing + pytest/index tests_writing tests_sandbox binman_testsdoc/develop/pytest/index.rst new file +21
-0@@ -0,0 +1,21 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +pytest Framework within U-Boot +============================== + +General +------- + +.. toctree:: + :maxdepth: 1 + + usage + +Individual tests +---------------- + +.. toctree:: + :maxdepth: 1 + + test_000_version + test_net_bootdoc/develop/pytest/test_000_version.rst new file +8
-0@@ -0,0 +1,8 @@ +test_000_version +================ + +.. automodule:: test_000_version + :synopsis: + :member-order: bysource + :members: + :undoc-members:doc/develop/pytest/test_net_boot.rst new file +8
-0@@ -0,0 +1,8 @@ +test_net_boot +============= + +.. automodule:: test_net_boot + :synopsis: + :member-order: bysource + :members: + :undoc-members:doc/develop/pytest/usage.rst renamed from doc/develop/py_testing.rst +1
-1@@ -13,7 +13,7 @@ results. Advantages of this approach are: U-Boot; there can be no disconnect. - There is no need to write or embed test-related code into U-Boot itself. It is asserted that writing test-related code in Python is simpler and more - flexible than writing it all in C. But see :doc:`tests_writing` for caveats + flexible than writing it all in C. But see :doc:`../tests_writing` for caveats and more discussion / analysis. - It is reasonably simple to interact with U-Boot in this way.doc/develop/testing.rst +2
-2@@ -33,7 +33,7 @@ You can also run a selection tests in parallel with:: make pcheck All of the above use the test/run script with a paremeter to select which tests -are run. See :doc:`py_testing` for more information. +are run. See :doc:`pytest/usage` for more information. Sandbox@@ -69,7 +69,7 @@ build:: ./test/py/test.py --bd sandbox_spl --build -k test_spl -See :doc:`py_testing` for more information about the pytest suite. +See :doc:`pytest/usage` for more information about the pytest suite. See :doc:`tests_sandbox` for how to run tests directly (not through pytest).doc/develop/tests_writing.rst +1
-1@@ -376,5 +376,5 @@ An example SPL test is spl_test_load(). Writing Python tests -------------------- -See :doc:`py_testing` for brief notes how to write Python tests. You +See :doc:`pytest/usage` for brief notes how to write Python tests. You should be able to use the existing tests in test/py/tests as examples.doc/sphinx/requirements.txt +1
-0@@ -15,6 +15,7 @@ six==1.16.0 snowballstemmer==2.2.0 Sphinx==8.1.3 sphinx-prompt==1.9.0 +sphinx-reredirects==0.1.5 sphinx-rtd-theme==3.0.1 sphinxcontrib-applehelp==2.0.0 sphinxcontrib-devhelp==2.0.0test/py/tests/test_000_version.py +6
-4@@ -2,10 +2,12 @@ # Copyright (c) 2015 Stephen Warren # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. -# pytest runs tests the order of their module path, which is related to the -# filename containing the test. This file is named such that it is sorted -# first, simply as a very basic sanity check of the functionality of the U-Boot -# command prompt. +""" +pytest runs tests the order of their module path, which is related to the +filename containing the test. This file is named such that it is sorted +first, simply as a very basic sanity check of the functionality of the U-Boot +command prompt. +""" def test_version(u_boot_console): """Test that the "version" command prints the U-Boot version."""test/py/tests/test_net_boot.py +89
-74@@ -1,11 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # (C) Copyright 2023, Advanced Micro Devices, Inc. -import pytest -import u_boot_utils -import test_net -import re - """ Note: This test relies on boardenv_* containing configuration values to define which the network environment available for testing. Without this, this test@@ -13,77 +8,88 @@ will be automatically skipped. For example: -# Details regarding a boot image file that may be read from a TFTP server. This -# variable may be omitted or set to None if TFTP boot testing is not possible -# or desired. -env__net_tftp_bootable_file = { - 'fn': 'image.ub', - 'addr': 0x10000000, - 'size': 5058624, - 'crc32': 'c2244b26', - 'pattern': 'Linux', - 'config': 'config@2', - 'timeout': 50000, - 'check_type': 'boot_error', - 'check_pattern': 'ERROR', -} - -# False or omitted if a TFTP boot test should be tested. -# If TFTP boot testing is not possible or desired, set this variable to True. -# For example: If FIT image is not proper to boot -env__tftp_boot_test_skip = False - -# Here is the example of FIT image configurations: -configurations { - default = "config@1"; - config@1 { - description = "Boot Linux kernel with config@1"; - kernel = "kernel@0"; - fdt = "fdt@0"; - ramdisk = "ramdisk@0"; - hash@1 { - algo = "sha1"; - }; - }; - config@2 { - description = "Boot Linux kernel with config@2"; - kernel = "kernel@1"; - fdt = "fdt@1"; - ramdisk = "ramdisk@1"; - hash@1 { - algo = "sha1"; - }; - }; -}; - -# Details regarding a file that may be read from a TFTP server. This variable -# may be omitted or set to None if PXE testing is not possible or desired. -env__net_pxe_bootable_file = { - 'fn': 'default', - 'addr': 0x10000000, - 'size': 74, - 'timeout': 50000, - 'pattern': 'Linux', - 'valid_label': '1', - 'invalid_label': '2', - 'exp_str_invalid': 'Skipping install for failure retrieving', - 'local_label': '3', - 'exp_str_local': 'missing environment variable: localcmd', - 'empty_label': '4', - 'exp_str_empty': 'No kernel given, skipping boot', - 'check_type': 'boot_error', - 'check_pattern': 'ERROR', -} - -# False if a PXE boot test should be tested. -# If PXE boot testing is not possible or desired, set this variable to True. -# For example: If pxe configuration file is not proper to boot -env__pxe_boot_test_skip = False - -# Here is the example of pxe configuration file ordered based on the execution -# flow: +.. code-block:: python + + # Details regarding a boot image file that may be read from a TFTP server. This + # variable may be omitted or set to None if TFTP boot testing is not possible + # or desired. + env__net_tftp_bootable_file = { + 'fn': 'image.ub', + 'addr': 0x10000000, + 'size': 5058624, + 'crc32': 'c2244b26', + 'pattern': 'Linux', + 'config': 'config@2', + 'timeout': 50000, + 'check_type': 'boot_error', + 'check_pattern': 'ERROR', + } + + # False or omitted if a TFTP boot test should be tested. + # If TFTP boot testing is not possible or desired, set this variable to True. + # For example: If FIT image is not proper to boot + env__tftp_boot_test_skip = False + + +Here is the example of FIT image configurations: + +.. code-block:: devicetree + + configurations { + default = "config@1"; + config@1 { + description = "Boot Linux kernel with config@1"; + kernel = "kernel@0"; + fdt = "fdt@0"; + ramdisk = "ramdisk@0"; + hash@1 { + algo = "sha1"; + }; + }; + config@2 { + description = "Boot Linux kernel with config@2"; + kernel = "kernel@1"; + fdt = "fdt@1"; + ramdisk = "ramdisk@1"; + hash@1 { + algo = "sha1"; + }; + }; + }; + +.. code-block:: python + + # Details regarding a file that may be read from a TFTP server. This variable + # may be omitted or set to None if PXE testing is not possible or desired. + env__net_pxe_bootable_file = { + 'fn': 'default', + 'addr': 0x10000000, + 'size': 74, + 'timeout': 50000, + 'pattern': 'Linux', + 'valid_label': '1', + 'invalid_label': '2', + 'exp_str_invalid': 'Skipping install for failure retrieving', + 'local_label': '3', + 'exp_str_local': 'missing environment variable: localcmd', + 'empty_label': '4', + 'exp_str_empty': 'No kernel given, skipping boot', + 'check_type': 'boot_error', + 'check_pattern': 'ERROR', + } + + # False if a PXE boot test should be tested. + # If PXE boot testing is not possible or desired, set this variable to True. + # For example: If pxe configuration file is not proper to boot + env__pxe_boot_test_skip = False + +Here is the example of pxe configuration file ordered based on the execution +flow: + 1) /tftpboot/pxelinux.cfg/default-arm-zynqmp +.. code-block:: + menu include pxelinux.cfg/default-arm timeout 50@@ -91,6 +97,8 @@ env__pxe_boot_test_skip = False 2) /tftpboot/pxelinux.cfg/default-arm +.. code-block:: + menu title Linux boot selections menu include pxelinux.cfg/default@@ -110,6 +118,8 @@ env__pxe_boot_test_skip = False 3) /tftpboot/pxelinux.cfg/default +.. code-block:: + label Linux menu label Boot kernel kernel Image@@ -117,6 +127,11 @@ env__pxe_boot_test_skip = False initrd rootfs.cpio.gz.u-boot """ +import pytest +import u_boot_utils +import test_net +import re + def setup_networking(u_boot_console): test_net.test_net_dhcp(u_boot_console) if not test_net.net_set_up:
Quoted 20 lines · Heinrich Schuchardt
Quoted 19 lines · Tom Rini
As there is support within the Sphinx framework to take Python docstrings and generate documentation from it, we can make use of that to more clearly and consistently document our pytests and how to configure them. To do this we:
- Add PYTHONPATH toDOC_TARGETSso that modules will be found, have CI install pytest module as well.
- Add the autodoc extension for Python and then redirects so we can move py_testing.html (which is heavily referenced in archives, etc).
- Create a doc/develop/pytest directory and move the existingpy_testingfile there, update references.
- Update thetest_000_version.pytest to have a docstring
- Move the imports intest_net_boot.pyso the docstring is in the correct place.
- Use code-block for all of the code blocks intest_net_boot.pyso they are rendered correctly in documentation.
- Adding these code-block lines makes the diff larger when read but a "git show -w" for example makes it clearer that the textual changes are removing '#' from lines so the output reads nicer.
Quoted 6 lines
Quoted 1 line
Signed-off-by Tom Rini <[email protected]>Some of the test functions seem to lack documentation:
test_net_boot.setup_networking()test_net_boot.setup_tftpboot_boot()
Yes. Most of the tests need more documentation and only have a minimal header comment.
Quoted 5 lines
Would you know what 000 in the following filename corresponds to?
test/py/tests/test_000_version.pyMaybe we should rename to
test_version.pyit before adding this patch.
Yes, it's an ordering trick to ensure that we run this trivial test first (and so can also fail out quickly). It should be documented.
Quoted 2 lines
Thanks. I'll take that to mean you're conceptually fine with this so I'll start on a real series that split the changes up and includes a follow-up "now document this test better".
Signature · 1 line
Tom
v2 cover Start improving pytest documentation
In reply to Tom RiniHey all,
This is a follow-up to the RFC I posted a few months back. Aside from rebasing, the only real change here is in the last patch where I document the functions in test_net_boot.py that Heinrich noted weren't documented before.
Signature · 1 line
Tom
PATCH v2 1/4 doc: Start improving our pytest documentation
Begin the work of documenting all of our pytests. To do this, we should have a directory under develop for it as there will be a large number of new files. As the current document is referenced externally in a number of locations, add the sphinx_reredirects module so that we can redirect from the old location to the new.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
---
doc/conf.py | 8 +++++++-
doc/develop/ci_testing.rst | 2 +-
doc/develop/index.rst | 2 +-
doc/develop/pytest/index.rst | 12 ++++++++++++
doc/develop/{py_testing.rst => pytest/usage.rst} | 2 +-
doc/develop/testing.rst | 4 ++--
doc/develop/tests_writing.rst | 2 +-
doc/sphinx/requirements.txt | 1 +
8 files changed, 26 insertions(+), 7 deletions(-)
create mode 100644 doc/develop/pytest/index.rst
rename doc/develop/{py_testing.rst => pytest/usage.rst} (99%)doc/conf.py +7 -1
@@ -47,7 +47,8 @@ needs_sphinx = '2.4.4' extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'kfigure', 'sphinx.ext.ifconfig', # 'automarkup', 'maintainers_include', 'sphinx.ext.autosectionlabel', - 'kernel_abi', 'kernel_feat', 'sphinx-prompt'] + 'kernel_abi', 'kernel_feat', 'sphinx-prompt', + 'sphinx_reredirects' ] # # cdomain is badly broken in Sphinx 3+. Leaving it out generates *most*
@@ -148,6 +149,11 @@ project = 'Das U-Boot' copyright = 'The U-Boot development community' author = 'The U-Boot development community' +# Pages we have moved after being heavily referenced externally +redirects = { + "develop/py_testing": "pytest/usage.html" +} + # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents.
doc/develop/ci_testing.rst +1 -1
@@ -18,7 +18,7 @@ be built with mingw to run on Windows. Each of the pipelines is written in such as way as to be a "world build" style test and as such we try and build all possible platforms. In addition, for all platforms that support being run in QEMU we run them in QEMU and use our pytest -suite. See :doc:`py_testing` for more information about those tests. +suite. See :doc:`pytest/usage` for more information about those tests. Azure Pipelines ---------------
doc/develop/index.rst +1 -1
@@ -82,7 +82,7 @@ Testing :maxdepth: 1 testing - py_testing + pytest/index tests_writing tests_sandbox binman_tests
doc/develop/pytest/index.rst new file +12 -0
@@ -0,0 +1,12 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +pytest Framework within U-Boot +============================== + +General +------- + +.. toctree:: + :maxdepth: 1 + + usage
doc/develop/pytest/usage.rst renamed from doc/develop/py_testing.rst +1 -1
@@ -13,7 +13,7 @@ results. Advantages of this approach are: U-Boot; there can be no disconnect. - There is no need to write or embed test-related code into U-Boot itself. It is asserted that writing test-related code in Python is simpler and more - flexible than writing it all in C. But see :doc:`tests_writing` for caveats + flexible than writing it all in C. But see :doc:`../tests_writing` for caveats and more discussion / analysis. - It is reasonably simple to interact with U-Boot in this way.
doc/develop/testing.rst +2 -2
@@ -33,7 +33,7 @@ You can also run a selection tests in parallel with:: make pcheck All of the above use the test/run script with a paremeter to select which tests -are run. See :doc:`py_testing` for more information. +are run. See :doc:`pytest/usage` for more information. Sandbox
@@ -69,7 +69,7 @@ build:: ./test/py/test.py --bd sandbox_spl --build -k test_spl -See :doc:`py_testing` for more information about the pytest suite. +See :doc:`pytest/usage` for more information about the pytest suite. See :doc:`tests_sandbox` for how to run tests directly (not through pytest).
doc/develop/tests_writing.rst +1 -1
@@ -376,5 +376,5 @@ An example SPL test is spl_test_load(). Writing Python tests -------------------- -See :doc:`py_testing` for brief notes how to write Python tests. You +See :doc:`pytest/usage` for brief notes how to write Python tests. You should be able to use the existing tests in test/py/tests as examples.
doc/sphinx/requirements.txt +1 -0
@@ -15,6 +15,7 @@ six==1.16.0 snowballstemmer==2.2.0 Sphinx==8.1.3 sphinx-prompt==1.9.0 +sphinx-reredirects==0.1.5 sphinx-rtd-theme==3.0.1 sphinxcontrib-applehelp==2.0.0 sphinxcontrib-devhelp==2.0.0
Signature · 1 line
2.43.0
Re: [PATCH v2 1/4] doc: Start improving our pytest documentation
Quoted 11 lines · Tom Rini
Begin the work of documenting all of our pytests. To do this, we should have a directory under develop for it as there will be a large number of new files. As the current document is referenced externally in a number of locations, add the
sphinx_reredirectsmodule so that we can redirect from the old location to the new.Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
Quoted 13 lines
---
doc/conf.py | 8 +++++++-
doc/develop/ci_testing.rst | 2 +-
doc/develop/index.rst | 2 +-
doc/develop/pytest/index.rst | 12 ++++++++++++
doc/develop/{py_testing.rst => pytest/usage.rst} | 2 +-
doc/develop/testing.rst | 4 ++--
doc/develop/tests_writing.rst | 2 +-
doc/sphinx/requirements.txt | 1 +
8 files changed, 26 insertions(+), 7 deletions(-)
create mode 100644 doc/develop/pytest/index.rst
rename doc/develop/{py_testing.rst => pytest/usage.rst} (99%)PATCH v2 2/4 doc: pytest: Framework for documenting tests and document test_000_version
In reply to Tom RiniIn order to easily document pytests, we need to include the autodoc extension. We also need to make sure that for building the docs, CI includes pytest and that we have PYTHONPATH configured such that it will find all of the tests and related files. Finally, we need to have our comments in the test file by in proper pydoc format in order to be included in the output.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
--- .azure-pipelines.yml | 2 +- .gitlab-ci.yml | 2 +- Makefile | 3 ++- doc/conf.py | 2 +- doc/develop/pytest/index.rst | 8 ++++++++ doc/develop/pytest/test_000_version.rst | 8 ++++++++ test/py/tests/test_000_version.py | 10 ++++++---- 7 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 doc/develop/pytest/test_000_version.rst
.azure-pipelines.yml +1 -1
@@ -92,7 +92,7 @@ stages: set -e python3 -m venv /tmp/venvhtml . /tmp/venvhtml/bin/activate - pip install -r doc/sphinx/requirements.txt + pip install -r doc/sphinx/requirements.txt pytest make htmldocs KDOC_WERROR=1 make infodocs
.gitlab-ci.yml +1 -1
@@ -164,7 +164,7 @@ docs: script: - python3 -m venv /tmp/venvhtml - . /tmp/venvhtml/bin/activate - - pip install -r doc/sphinx/requirements.txt + - pip install -r doc/sphinx/requirements.txt pytest - make htmldocs KDOC_WERROR=1 - make infodocs
Makefile +2 -1
@@ -2448,7 +2448,8 @@ DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs texinfodocs infodocs PHONY += $(DOC_TARGETS) $(DOC_TARGETS): scripts_basic FORCE - $(Q)$(MAKE) $(build)=doc $@ + $(Q)PYTHONPATH=$(srctree)/test/py/tests:$(srctree)/test/py \ + $(MAKE) $(build)=doc $@ PHONY += checkstack ubootrelease ubootversion
doc/conf.py +1 -1
@@ -48,7 +48,7 @@ extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'kfigure', 'sphinx.ext.ifconfig', # 'automarkup', 'maintainers_include', 'sphinx.ext.autosectionlabel', 'kernel_abi', 'kernel_feat', 'sphinx-prompt', - 'sphinx_reredirects' ] + 'sphinx_reredirects', 'sphinx.ext.autodoc' ] # # cdomain is badly broken in Sphinx 3+. Leaving it out generates *most*
doc/develop/pytest/index.rst +8 -0
@@ -10,3 +10,11 @@ General :maxdepth: 1 usage + +Individual tests +---------------- + +.. toctree:: + :maxdepth: 1 + + test_000_version
doc/develop/pytest/test_000_version.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_000_version +================ + +.. automodule:: test_000_version + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_000_version.py +6 -4
@@ -2,10 +2,12 @@ # Copyright (c) 2015 Stephen Warren # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. -# pytest runs tests the order of their module path, which is related to the -# filename containing the test. This file is named such that it is sorted -# first, simply as a very basic sanity check of the functionality of the U-Boot -# command prompt. +""" +pytest runs tests the order of their module path, which is related to the +filename containing the test. This file is named such that it is sorted +first, simply as a very basic sanity check of the functionality of the U-Boot +command prompt. +""" def test_version(ubman): """Test that the "version" command prints the U-Boot version."""
Signature · 1 line
2.43.0
Re: [PATCH v2 2/4] doc: pytest: Framework for documenting tests and document test_000_version
Hi Tom,
Quoted 12 lines · Tom Rini
In order to easily document pytests, we need to include the autodoc extension. We also need to make sure that for building the docs, CI includes pytest and that we have PYTHONPATH configured such that it will find all of the tests and related files. Finally, we need to have our comments in the test file by in proper pydoc format in order to be included in the output.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
Quoted 10 lines
--- .azure-pipelines.yml | 2 +- .gitlab-ci.yml | 2 +- Makefile | 3 ++- doc/conf.py | 2 +- doc/develop/pytest/index.rst | 8 ++++++++ doc/develop/pytest/test_000_version.rst | 8 ++++++++ test/py/tests/test_000_version.py | 10 ++++++---- 7 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 doc/develop/pytest/test_000_version.rst
Thank you for doing this.
Quoted 89 lines
.azure-pipelines.yml +1
-1@@ -92,7 +92,7 @@ stages: set -e python3 -m venv /tmp/venvhtml . /tmp/venvhtml/bin/activate - pip install -r doc/sphinx/requirements.txt + pip install -r doc/sphinx/requirements.txt pytest make htmldocs KDOC_WERROR=1 make infodocs.gitlab-ci.yml +1
-1@@ -164,7 +164,7 @@ docs: script: - python3 -m venv /tmp/venvhtml - . /tmp/venvhtml/bin/activate - - pip install -r doc/sphinx/requirements.txt + - pip install -r doc/sphinx/requirements.txt pytest - make htmldocs KDOC_WERROR=1 - make infodocsMakefile +2
-1@@ -2448,7 +2448,8 @@ DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs texinfodocs infodocs PHONY += $(DOC_TARGETS) $(DOC_TARGETS): scripts_basic FORCE - $(Q)$(MAKE) $(build)=doc $@ + $(Q)PYTHONPATH=$(srctree)/test/py/tests:$(srctree)/test/py \ + $(MAKE) $(build)=doc $@ PHONY += checkstack ubootrelease ubootversiondoc/conf.py +1
-1@@ -48,7 +48,7 @@ extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'kfigure', 'sphinx.ext.ifconfig', # 'automarkup', 'maintainers_include', 'sphinx.ext.autosectionlabel', 'kernel_abi', 'kernel_feat', 'sphinx-prompt', - 'sphinx_reredirects' ] + 'sphinx_reredirects', 'sphinx.ext.autodoc' ] # # cdomain is badly broken in Sphinx 3+. Leaving it out generates *most*doc/develop/pytest/index.rst +8
-0@@ -10,3 +10,11 @@ General :maxdepth: 1 usage + +Individual tests +---------------- + +.. toctree:: + :maxdepth: 1 + + test_000_versiondoc/develop/pytest/test_000_version.rst new file +8
-0@@ -0,0 +1,8 @@ +test_000_version +================ + +.. automodule:: test_000_version + :synopsis: + :member-order: bysource + :members: + :undoc-members:test/py/tests/test_000_version.py +0
-0
test/py/tests/test_000_version.py line 6
Quoted 9 lines
test/py/tests/test_000_version.py +2
-4@@ -2,10 +2,12 @@ # Copyright (c) 2015 Stephen Warren # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. -# pytest runs tests the order of their module path, which is related to the -# filename containing the test. This file is named such that it is sorted -# first, simply as a very basic sanity check of the functionality of the U-Boot -# command prompt. +""" +pytest runs tests the order of their module path, which is related to the
in the order
Quoted 10 lines
test/py/tests/test_000_version.py +4
-1+filename containing the test. This file is named such that it is sorted +first, simply as a very basic sanity check of the functionality of the U-Boot +command prompt. +""" def test_version(ubman): """Test that the "version" command prints the U-Boot version.""" --2.43.0
Regards,
Simon
Re: [PATCH v2 2/4] doc: pytest: Framework for documenting tests and document test_000_version
In reply to Tom RiniHi Tom,
Quoted 27 lines · Tom Rini
In order to easily document pytests, we need to include the autodoc extension. We also need to make sure that for building the docs, CI includes pytest and that we have PYTHONPATH configured such that it will find all of the tests and related files. Finally, we need to have our comments in the test file by in proper pydoc format in order to be included in the output.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>--- .azure-pipelines.yml | 2 +- .gitlab-ci.yml | 2 +- Makefile | 3 ++- doc/conf.py | 2 +- doc/develop/pytest/index.rst | 8 ++++++++ doc/develop/pytest/test_000_version.rst | 8 ++++++++ test/py/tests/test_000_version.py | 10 ++++++---- 7 files changed, 27 insertions(+), 8 deletions(-)create mode 100644
doc/develop/pytest/test_000_version.rst.azure-pipelines.yml +0
-0
.azure-pipelines.yml stages: · line 95
Quoted 5 lines
.azure-pipelines.yml +1
-1@@ -92,7 +92,7 @@ stages: set -e python3 -m venv /tmp/venvhtml . /tmp/venvhtml/bin/activate - pip install -r doc/sphinx/requirements.txt + pip install -r doc/sphinx/requirements.txt pytest
Shouldn't we force a specific version of pytest like we would if it were part of doc/sphinx/requirements.txt?
Quoted 49 lines
.azure-pipelines.yml +0
-0make htmldocs KDOC_WERROR=1 make infodocs.gitlab-ci.yml +1
-1@@ -164,7 +164,7 @@ docs: script: - python3 -m venv /tmp/venvhtml - . /tmp/venvhtml/bin/activate - - pip install -r doc/sphinx/requirements.txt + - pip install -r doc/sphinx/requirements.txt pytest - make htmldocs KDOC_WERROR=1 - make infodocsMakefile +2
-1@@ -2448,7 +2448,8 @@ DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs texinfodocs infodocs PHONY += $(DOC_TARGETS) $(DOC_TARGETS): scripts_basic FORCE - $(Q)$(MAKE) $(build)=doc $@ + $(Q)PYTHONPATH=$(srctree)/test/py/tests:$(srctree)/test/py \ + $(MAKE) $(build)=doc $@ PHONY += checkstack ubootrelease ubootversiondoc/conf.py +1
-1@@ -48,7 +48,7 @@ extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'kfigure', 'sphinx.ext.ifconfig', # 'automarkup', 'maintainers_include', 'sphinx.ext.autosectionlabel', 'kernel_abi', 'kernel_feat', 'sphinx-prompt', - 'sphinx_reredirects' ] + 'sphinx_reredirects', 'sphinx.ext.autodoc' ] # # cdomain is badly broken in Sphinx 3+. Leaving it out generates *most*doc/develop/pytest/index.rst +0
-0@@ -10,3 +10,11 @@ General :maxdepth: 1
doc/develop/pytest/index.rst General · line 20
Quoted 10 lines
doc/develop/pytest/index.rst +8
-0usage + +Individual tests +---------------- + +.. toctree:: + :maxdepth: 1 + + test_000_version
Can I recommend using a glob here to avoid having to constantly modify the index.rst whenever a new file needs to be added to it?
.. toctree::
:maxdepth: 1
:glob:
test_*
for example, c.f. https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-option-toctree-glob
Cheers,
Quentin
Re: [PATCH v2 2/4] doc: pytest: Framework for documenting tests and document test_000_version
Quoted 25 lines · Quentin Schulz
Hi Tom,
Quoted 22 lines · Tom Rini
In order to easily document pytests, we need to include the autodoc extension. We also need to make sure that for building the docs, CI includes pytest and that we have PYTHONPATH configured such that it will find all of the tests and related files. Finally, we need to have our comments in the test file by in proper pydoc format in order to be included in the output.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>--- .azure-pipelines.yml | 2 +- .gitlab-ci.yml | 2 +- Makefile | 3 ++- doc/conf.py | 2 +- doc/develop/pytest/index.rst | 8 ++++++++ doc/develop/pytest/test_000_version.rst | 8 ++++++++ test/py/tests/test_000_version.py | 10 ++++++---- 7 files changed, 27 insertions(+), 8 deletions(-)create mode 100644
doc/develop/pytest/test_000_version.rst
Quoted 13 lines
.azure-pipelines.yml stages: · line 95
Quoted 10 lines
.azure-pipelines.yml +1
-1@@ -92,7 +92,7 @@ stages: set -e python3 -m venv /tmp/venvhtml . /tmp/venvhtml/bin/activate - pip install -r doc/sphinx/requirements.txt + pip install -r doc/sphinx/requirements.txt pytestShouldn't we force a specific version of pytest like we would if it were part of
doc/sphinx/requirements.txt?
It's a good question. I don't know and I didn't want to drag the whole of test/py/requirements.txt here nor have to worry about the pin in 2 places. I am hoping that for documentation needs this will be OK.
Quoted 58 lines
Quoted 44 lines
.azure-pipelines.yml +0
-0make htmldocs KDOC_WERROR=1 make infodocs.gitlab-ci.yml +1
-1@@ -164,7 +164,7 @@ docs: script: - python3 -m venv /tmp/venvhtml - . /tmp/venvhtml/bin/activate - - pip install -r doc/sphinx/requirements.txt + - pip install -r doc/sphinx/requirements.txt pytest - make htmldocs KDOC_WERROR=1 - make infodocsMakefile +2
-1@@ -2448,7 +2448,8 @@ DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs texinfodocs infodocs PHONY += $(DOC_TARGETS) $(DOC_TARGETS): scripts_basic FORCE - $(Q)$(MAKE) $(build)=doc $@ + $(Q)PYTHONPATH=$(srctree)/test/py/tests:$(srctree)/test/py \ + $(MAKE) $(build)=doc $@ PHONY += checkstack ubootrelease ubootversiondoc/conf.py +1
-1@@ -48,7 +48,7 @@ extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'kfigure', 'sphinx.ext.ifconfig', # 'automarkup', 'maintainers_include', 'sphinx.ext.autosectionlabel', 'kernel_abi', 'kernel_feat', 'sphinx-prompt', - 'sphinx_reredirects' ] + 'sphinx_reredirects', 'sphinx.ext.autodoc' ] # # cdomain is badly broken in Sphinx 3+. Leaving it out generates *most*doc/develop/pytest/index.rst +0
-0doc/develop/pytest/index.rst General · line 19
Quoted 10 lines
doc/develop/pytest/index.rst +8
-0@@ -10,3 +10,11 @@ General :maxdepth: 1 usage + +Individual tests +---------------- + +.. toctree:: + :maxdepth: 1 + + test_000_versionCan I recommend using a glob here to avoid having to constantly modify the
index.rstwhenever a new file needs to be added to it?
Quoted 7 lines
.. toctree::
:maxdepth: 1 :glob: test_*for example, c.f. https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-option-toctree-glob
Oh neat. Yes, that should be done instead. I wasn't expecting Heinrich to pick it all up so quick, do you want to post a patch or should I do it and Suggested-by you? Thanks!
Quoted 3 lines
Cheers,
Quentin
Signature · 1 line
Tom
Re: [PATCH v2 2/4] doc: pytest: Framework for documenting tests and document test_000_version
Hi Tom,
Quoted 40 lines · Tom Rini
Quoted 25 lines · Quentin Schulz
Hi Tom,
Quoted 22 lines · Tom Rini
In order to easily document pytests, we need to include the autodoc extension. We also need to make sure that for building the docs, CI includes pytest and that we have PYTHONPATH configured such that it will find all of the tests and related files. Finally, we need to have our comments in the test file by in proper pydoc format in order to be included in the output.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>--- .azure-pipelines.yml | 2 +- .gitlab-ci.yml | 2 +- Makefile | 3 ++- doc/conf.py | 2 +- doc/develop/pytest/index.rst | 8 ++++++++ doc/develop/pytest/test_000_version.rst | 8 ++++++++ test/py/tests/test_000_version.py | 10 ++++++---- 7 files changed, 27 insertions(+), 8 deletions(-)create mode 100644
doc/develop/pytest/test_000_version.rstQuoted 13 lines
.azure-pipelines.yml stages: · line 95
Quoted 10 lines
.azure-pipelines.yml +1
-1@@ -92,7 +92,7 @@ stages: set -e python3 -m venv /tmp/venvhtml . /tmp/venvhtml/bin/activate - pip install -r doc/sphinx/requirements.txt + pip install -r doc/sphinx/requirements.txt pytestShouldn't we force a specific version of pytest like we would if it were part of
doc/sphinx/requirements.txt?
Quoted 4 lines
It's a good question. I don't know and I didn't want to drag the whole of
test/py/requirements.txthere nor have to worry about the pin in 2 places. I am hoping that for documentation needs this will be OK.
/me shrugs
Time will tell.
Quoted 62 lines
Quoted 62 lines
Quoted 44 lines
.azure-pipelines.yml +0
-0make htmldocs KDOC_WERROR=1 make infodocs.gitlab-ci.yml +1
-1@@ -164,7 +164,7 @@ docs: script: - python3 -m venv /tmp/venvhtml - . /tmp/venvhtml/bin/activate - - pip install -r doc/sphinx/requirements.txt + - pip install -r doc/sphinx/requirements.txt pytest - make htmldocs KDOC_WERROR=1 - make infodocsMakefile +2
-1@@ -2448,7 +2448,8 @@ DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs texinfodocs infodocs PHONY += $(DOC_TARGETS) $(DOC_TARGETS): scripts_basic FORCE - $(Q)$(MAKE) $(build)=doc $@ + $(Q)PYTHONPATH=$(srctree)/test/py/tests:$(srctree)/test/py \ + $(MAKE) $(build)=doc $@ PHONY += checkstack ubootrelease ubootversiondoc/conf.py +1
-1@@ -48,7 +48,7 @@ extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'kfigure', 'sphinx.ext.ifconfig', # 'automarkup', 'maintainers_include', 'sphinx.ext.autosectionlabel', 'kernel_abi', 'kernel_feat', 'sphinx-prompt', - 'sphinx_reredirects' ] + 'sphinx_reredirects', 'sphinx.ext.autodoc' ] # # cdomain is badly broken in Sphinx 3+. Leaving it out generates *most*doc/develop/pytest/index.rst +0
-0doc/develop/pytest/index.rst General · line 19
Quoted 10 lines
doc/develop/pytest/index.rst +8
-0@@ -10,3 +10,11 @@ General :maxdepth: 1 usage + +Individual tests +---------------- + +.. toctree:: + :maxdepth: 1 + + test_000_versionCan I recommend using a glob here to avoid having to constantly modify the
index.rstwhenever a new file needs to be added to it?.. toctree::
:maxdepth: 1 :glob:
Quoted 8 lines
Quoted 3 lines
test_*for example, c.f. https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-option-toctree-glob
Oh neat. Yes, that should be done instead. I wasn't expecting Heinrich to pick it all up so quick, do you want to post a patch or should I do it and Suggested-by you? Thanks!
Please go ahead with posting the patch :)
Thanks!
Quentin
PATCH v2 3/4 doc: pytest: Document the test_net_boot test
In reply to Tom RiniAdd the test_net_boot.py test to the generated documentation. While most of this was already commented correctly for inclusion the biggest problem was examples of code without a code-block notation. This in turn broke parsing. Add the missing notations. We also must have the comment prior to any import lines or it will not be seen as a comment on the overall file and thus not included.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_net_boot.rst | 8 ++ test/py/tests/test_net_boot.py | 163 +++++++++++++++------------ 3 files changed, 98 insertions(+), 74 deletions(-) create mode 100644 doc/develop/pytest/test_net_boot.rst
doc/develop/pytest/index.rst +1 -0
@@ -18,3 +18,4 @@ Individual tests :maxdepth: 1 test_000_version + test_net_boot
doc/develop/pytest/test_net_boot.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_net_boot +============= + +.. automodule:: test_net_boot + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_net_boot.py +89 -74
195 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v2 3/4] doc: pytest: Document the test_net_boot test
Quoted 12 lines · Tom Rini
Add the
test_net_boot.pytest to the generated documentation. While most of this was already commented correctly for inclusion the biggest problem was examples of code without a code-block notation. This in turn broke parsing. Add the missing notations. We also must have the comment prior to any import lines or it will not be seen as a comment on the overall file and thus not included.Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
Quoted 7 lines
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_net_boot.rst | 8 ++ test/py/tests/test_net_boot.py | 163 +++++++++++++++------------ 3 files changed, 98 insertions(+), 74 deletions(-) create mode 100644 doc/develop/pytest/test_net_boot.rst
Can we add some default binaries to the tree, or somewhere else?
Regards,
Simon
Re: [PATCH v2 3/4] doc: pytest: Document the test_net_boot test
Quoted 21 lines · Simon Glass
Quoted 12 lines · Tom Rini
Add the
test_net_boot.pytest to the generated documentation. While most of this was already commented correctly for inclusion the biggest problem was examples of code without a code-block notation. This in turn broke parsing. Add the missing notations. We also must have the comment prior to any import lines or it will not be seen as a comment on the overall file and thus not included.Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>Quoted 7 lines
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_net_boot.rst | 8 ++ test/py/tests/test_net_boot.py | 163 +++++++++++++++------------ 3 files changed, 98 insertions(+), 74 deletions(-) create mode 100644 doc/develop/pytest/test_net_boot.rst
Quoted 3 lines
Reviewed-by Simon Glass <[email protected]>Can we add some default binaries to the tree, or somewhere else?
No, I don't think that's a good idea. It needs to be something that will actually boot on the hardware in question.
Signature · 1 line
Tom
PATCH v2 4/4 test: test_net_boot: Add more comments
In reply to Tom RiniSome of the functions were missing pydoc comments. Add them so they will be included in the documentation.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
--- test/py/tests/test_net_boot.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
test/py/tests/test_net_boot.py +14 -0
@@ -133,11 +133,21 @@ import test_net import re def setup_networking(ubman): + """Setup networking + + Making use of the test_net test, first try and configure networking via + DHCP. If this fails, fall back to static configuration. + """ test_net.test_net_dhcp(ubman) if not test_net.net_set_up: test_net.test_net_setup_static(ubman) def setup_tftpboot_boot(ubman): + """Setup for the tftpboot 'boot' test + + We check that a file to use has been configured. If it has, we download it + and ensure it has the expected crc32 value. + """ f = ubman.config.env.get('env__net_tftp_bootable_file', None) if not f: pytest.skip('No TFTP bootable file to read')
@@ -213,6 +223,10 @@ def test_net_tftpboot_boot(ubman): ubman.cleanup_spawn() def setup_pxe_boot(ubman): + """Setup for the PXE 'boot' test + + Make sure that the file to load via PXE boot has been configured. + """ f = ubman.config.env.get('env__net_pxe_bootable_file', None) if not f: pytest.skip('No PXE bootable file to read')
Signature · 1 line
2.43.0
Re: [PATCH v2 4/4] test: test_net_boot: Add more comments
Quoted 4 lines · Tom Rini
Some of the functions were missing pydoc comments. Add them so they will be included in the documentation.
Quoted 9 lines
Reported-by Heinrich Schuchardt <[email protected]>Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>--- test/py/tests/test_net_boot.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
cover Document more pytests
In reply to Tom RiniHey all,
As a follow-up to my previous series about adding pytests to the documentation, this small series adds and updates the tests which I had been enabling in my labs. Making the existing examples easier to find will hopefully make it easier for other labs to enable them.
Signature · 1 line
Tom
PATCH 1/3 doc: pytest: Document the test_net test
Add this test to the documentation. While the diff appears large at first, the only changes within the test are to move the imports to follow the pydoc comment and then to code-block and indent the example configuration.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_net.rst | 8 ++ test/py/tests/test_net.py | 152 ++++++++++++++++---------------- 3 files changed, 86 insertions(+), 75 deletions(-) create mode 100644 doc/develop/pytest/test_net.rst
doc/develop/pytest/index.rst +1 -0
@@ -18,4 +18,5 @@ Individual tests :maxdepth: 1 test_000_version + test_net test_net_boot
doc/develop/pytest/test_net.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_net +======== + +.. automodule:: test_net + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_net.py +77 -75
166 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 1/3] doc: pytest: Document the test_net test
Quoted 10 lines · Tom Rini
Add this test to the documentation. While the diff appears large at first, the only changes within the test are to move the imports to follow the pydoc comment and then to code-block and indent the example configuration.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
Quoted 6 lines
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_net.rst | 8 ++ test/py/tests/test_net.py | 152 ++++++++++++++++---------------- 3 files changed, 86 insertions(+), 75 deletions(-) create mode 100644 doc/develop/pytest/test_net.rst
PATCH 2/3 doc: pytest: Document the test_bootstage test
In reply to Tom RiniAdd this test to the documentation. We need to move the import to follow the main comment so that it renders correctly, and add a code-block annotation to the example and indent it correctly. Next, neither of the functions had comments themselves, so document them now.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_bootstage.rst | 8 ++++++ test/py/tests/test_bootstage.py | 35 +++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 doc/develop/pytest/test_bootstage.rst
doc/develop/pytest/index.rst +1 -0
@@ -18,5 +18,6 @@ Individual tests :maxdepth: 1 test_000_version + test_bootstage test_net test_net_boot
doc/develop/pytest/test_bootstage.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_bootstage +============== + +.. automodule:: test_bootstage + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_bootstage.py +28 -7
@@ -1,8 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # (C) Copyright 2023, Advanced Micro Devices, Inc. -import pytest - """ Test the bootstage command.
@@ -15,16 +13,32 @@ common/bootstage.c). Without this, bootstage stash and unstash tests will be automatically skipped. For example: -env__bootstage_cmd_file = { - 'addr': 0x200000, - 'size': 0x1000, - 'bootstage_magic_addr': 0xb00757a3, -} + +.. code-block:: python + + env__bootstage_cmd_file = { + 'addr': 0x200000, + 'size': 0x1000, + 'bootstage_magic_addr': 0xb00757a3, + } """ +import pytest + @pytest.mark.buildconfigspec('bootstage') @pytest.mark.buildconfigspec('cmd_bootstage') def test_bootstage_report(ubman): + """Test the bootstage report subcommand + + This will run the 'bootstage report' subcommand and ensure that we are + reporting: + + - A timer summary in microseconds + - The accumulated time + - That at least the phrase 'dm_r' is in the output + + Note that the time values are not checked. + """ output = ubman.run_command('bootstage report') assert 'Timer summary in microseconds' in output assert 'Accumulated time:' in output
@@ -34,6 +48,13 @@ def test_bootstage_report(ubman): @pytest.mark.buildconfigspec('cmd_bootstage') @pytest.mark.buildconfigspec('bootstage_stash') def test_bootstage_stash_and_unstash(ubman): + """Test the bootstage stash and unstash subcommands + + After checking that we have configured an environment file to use, we will + use the stash subcommand to save information. Then we will use the md + command to verify the contents in memory. Finally we confirm the unstash + subcommand runs successfully. + """ f = ubman.config.env.get('env__bootstage_cmd_file', None) if not f: pytest.skip('No bootstage environment file is defined')
Signature · 1 line
2.43.0
Re: [PATCH 2/3] doc: pytest: Document the test_bootstage test
Quoted 10 lines · Tom Rini
Add this test to the documentation. We need to move the import to follow the main comment so that it renders correctly, and add a code-block annotation to the example and indent it correctly. Next, neither of the functions had comments themselves, so document them now.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
Quoted 6 lines
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_bootstage.rst | 8 ++++++ test/py/tests/test_bootstage.py | 35 +++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 doc/develop/pytest/test_bootstage.rst
PATCH 3/3 doc: pytest: Document the test_efi_loader test
In reply to Tom RiniAdd this test to the documentation. We need to add a code-block annotation to the example and indent it correctly. We also need to document the do_test_efi_helloworld_net function and that in turn means changing the documentation to test_efi_helloworld_net_http and test_efi_helloworld_net_tftp to reflect what is and isn't done in those functions themselves now.
---
I honestly wasn't sure if this merits a fixes tag for commit d2056e2ed03f ("test/py: test_efi_loader: add HTTP (wget) test for the EFI loader") or not.
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_efi_loader.rst | 8 +++ test/py/tests/test_efi_loader.py | 87 ++++++++++++++------------ 3 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 doc/develop/pytest/test_efi_loader.rst
doc/develop/pytest/index.rst +1 -0
@@ -19,5 +19,6 @@ Individual tests test_000_version test_bootstage + test_efi_loader test_net test_net_boot
doc/develop/pytest/test_efi_loader.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_efi_loader +=============== + +.. automodule:: test_efi_loader + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_efi_loader.py +46 -41
111 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH 3/3] doc: pytest: Document the test_efi_loader test
Quoted 17 lines · Tom Rini
Add this test to the documentation. We need to add a code-block annotation to the example and indent it correctly. We also need to document the
do_test_efi_helloworld_netfunction and that in turn means changing the documentation totest_efi_helloworld_net_httpandtest_efi_helloworld_net_tftpto reflect what is and isn't done in those functions themselves now.Signed-off-by Tom Rini <[email protected]>---
I honestly wasn't sure if this merits a fixes tag for commitd2056e2ed03f("test/py:test_efi_loader: add HTTP (wget) test for the EFI loader") or not.Cc Jerome Forissier <[email protected]>Cc Heinrich Schuchardt <[email protected]>Cc Simon Glass <[email protected]>
Quoted 7 lines
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_efi_loader.rst | 8 +++ test/py/tests/test_efi_loader.py | 87 ++++++++++++++------------ 3 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 doc/develop/pytest/test_efi_loader.rst
cover doc: Document remaining test_b* tests
In reply to Tom RiniHey all,
This short series is a follow-up to my last series. It could have been longer, but I think this is a good point to get some feedback on a few points.
As background, something I wondered about and the answer seems to be No is, can we automatically take things like:
@pytest.mark.buildconfigspec('cmd_button')
and get some nice output? Since we can't that limits the value, possibly, of generating some documentation.
First, as this series shows, is there value in documenting tests which do not require additional configuration? We have some tests with no comments and some that are fully commented, but at the end of the day when trying to run these tests, pytest will already say helpful things like not being supported on a given platform, or not run because something isn't enabled in the build. Spelling that out in generated documentation would require duplication of work.
Second, is there value in documenting arguments? Especially ones like "ubman" that are just required and always present?
Third, should we document internal functions too, or just the tests? I would be inclined to say no unless they're expected to be re-used. The test_net functions to bring up the networking are an example that of reuse that should be documented for example.
Signature · 1 line
Tom
PATCH 1/3 doc: pytest: Document the test_bind test
Add this test to the documentation. None of the functions had comments, so attempt to explain what each does.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_bind.rst | 8 ++++++++ test/py/tests/test_bind.py | 12 ++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 doc/develop/pytest/test_bind.rst
doc/develop/pytest/index.rst +1 -0
@@ -18,6 +18,7 @@ Individual tests :maxdepth: 1 test_000_version + test_bind test_bootstage test_efi_loader test_net
doc/develop/pytest/test_bind.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_bind +========= + +.. automodule:: test_bind + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_bind.py +12 -0
@@ -7,6 +7,7 @@ import re import pytest def in_tree(response, name, uclass, drv, depth, last_child): + """A helper function to confirm contents of the device tree """ lines = [x.strip() for x in response.splitlines()] leaf = '' if depth != 0:
@@ -28,7 +29,12 @@ def in_tree(response, name, uclass, drv, depth, last_child): @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_bind') def test_bind_unbind_with_node(ubman): + """Test the bind and unbind commands of a node + Verify that the dm tree output contains some expected nodes, and then bind + and unbind a USB via node device while verifying that the dm tree output + matches the expected values at each step. + """ tree = ubman.run_command('dm tree') assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True) assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
@@ -106,6 +112,7 @@ def test_bind_unbind_with_node(ubman): assert response == '' def get_next_line(tree, name): + """A helper function to strip content out of dm tree output""" treelines = [x.strip() for x in tree.splitlines() if x.strip()] child_line = '' for idx, line in enumerate(treelines):
@@ -121,6 +128,11 @@ def get_next_line(tree, name): @pytest.mark.buildconfigspec('cmd_bind') @pytest.mark.singlethread def test_bind_unbind_with_uclass(ubman): + """Test the bind and unbind commands of a class + + Bind and unbind the simple_bus class while verifying that the dm tree + output matches the expected values at each step. + """ #bind /bind-test response = ubman.run_command('bind /bind-test simple_bus') assert response == ''
Signature · 1 line
2.43.0
Re: [PATCH 1/3] doc: pytest: Document the test_bind test
Quoted 8 lines · Tom Rini
Add this test to the documentation. None of the functions had comments, so attempt to explain what each does.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
Quoted 7 lines
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_bind.rst | 8 ++++++++ test/py/tests/test_bind.py | 12 ++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 doc/develop/pytest/test_bind.rst
PATCH 2/3 doc: pytest: Document the test_bootmenu test
In reply to Tom RiniAdd this test to the documentation. There was already a function comment that included the argument, so convert it to the right style to be rendered correctly in output.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_bootmenu.rst | 8 ++++++++ test/py/tests/test_bootmenu.py | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 doc/develop/pytest/test_bootmenu.rst
doc/develop/pytest/index.rst +1 -0
@@ -19,6 +19,7 @@ Individual tests test_000_version test_bind + test_bootmenu test_bootstage test_efi_loader test_net
doc/develop/pytest/test_bootmenu.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_bootmenu +============= + +.. automodule:: test_bootmenu + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_bootmenu.py +2 -2
@@ -8,9 +8,9 @@ import pytest def test_bootmenu(ubman): """Test bootmenu - ubman -- U-Boot console + Args: + ubman: U-Boot console """ - with ubman.temporary_timeout(500): ubman.run_command('setenv bootmenu_default 1') ubman.run_command('setenv bootmenu_0 test 1=echo ok 1')
Signature · 1 line
2.43.0
Re: [PATCH 2/3] doc: pytest: Document the test_bootmenu test
Quoted 9 lines · Tom Rini
Add this test to the documentation. There was already a function comment that included the argument, so convert it to the right style to be rendered correctly in output.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
Quoted 6 lines
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_bootmenu.rst | 8 ++++++++ test/py/tests/test_bootmenu.py | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 doc/develop/pytest/test_bootmenu.rst
BTW ubman is a little more than the console right now, but I suppose that doesn't matter.
Quoted 46 lines
doc/develop/pytest/index.rst +1
-0@@ -19,6 +19,7 @@ Individual tests test_000_version test_bind + test_bootmenu test_bootstage test_efi_loader test_netdoc/develop/pytest/test_bootmenu.rst new file +8
-0@@ -0,0 +1,8 @@ +test_bootmenu +============= + +.. automodule:: test_bootmenu + :synopsis: + :member-order: bysource + :members: + :undoc-members:test/py/tests/test_bootmenu.py +2
-3@@ -8,9 +8,9 @@ import pytest def test_bootmenu(ubman): """Test bootmenu - ubman -- U-Boot console + Args: + ubman: U-Boot console """ - with ubman.temporary_timeout(500): ubman.run_command('setenv bootmenu_default 1') ubman.run_command('setenv bootmenu_0 test 1=echo ok 1') --2.43.0
PATCH 3/3 doc: pytest: Document the test_button test
In reply to Tom RiniAdd this test to the documentation. No changes to the test itself were required.
---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_button.rst | 8 ++++++++ test/py/tests/test_button.py | 2 ++ 3 files changed, 11 insertions(+) create mode 100644 doc/develop/pytest/test_button.rst
doc/develop/pytest/index.rst +1 -0
@@ -21,6 +21,7 @@ Individual tests test_bind test_bootmenu test_bootstage + test_button test_efi_loader test_net test_net_boot
doc/develop/pytest/test_button.rst new file +8 -0
@@ -0,0 +1,8 @@ +test_button +=========== + +.. automodule:: test_button + :synopsis: + :member-order: bysource + :members: + :undoc-members:
test/py/tests/test_button.py +2 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0+ +"""Tests for the button command""" + import pytest @pytest.mark.boardspec('sandbox')
Signature · 1 line
2.43.0
Re: [PATCH 3/3] doc: pytest: Document the test_button test
Quoted 8 lines · Tom Rini
Add this test to the documentation. No changes to the test itself were required.
Signed-off-by Tom Rini <[email protected]>---
Cc: Heinrich Schuchardt <[email protected]>
Cc: Simon Glass <[email protected]>
Quoted 6 lines
--- doc/develop/pytest/index.rst | 1 + doc/develop/pytest/test_button.rst | 8 ++++++++ test/py/tests/test_button.py | 2 ++ 3 files changed, 11 insertions(+) create mode 100644 doc/develop/pytest/test_button.rst
Quoted 42 lines
doc/develop/pytest/index.rst +1
-0@@ -21,6 +21,7 @@ Individual tests test_bind test_bootmenu test_bootstage + test_button test_efi_loader test_net test_net_bootdoc/develop/pytest/test_button.rst new file +8
-0@@ -0,0 +1,8 @@ +test_button +=========== + +.. automodule:: test_button + :synopsis: + :member-order: bysource + :members: + :undoc-members:test/py/tests/test_button.py +2
-1@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0+ +"""Tests for the button command""" + import pytest @pytest.mark.boardspec('sandbox') --2.43.0
Re: [PATCH 0/3] doc: Document remaining test_b* tests
In reply to Tom RiniHi Tom,
Quoted 13 lines · Tom Rini
Hey all,
This short series is a follow-up to my last series. It could have been longer, but I think this is a good point to get some feedback on a few points.
As background, something I wondered about and the answer seems to be No is, can we automatically take things like:
@pytest.mark.buildconfigspec('cmd_button')
and get some nice output? Since we can't that limits the value, possibly, of generating some documentation.
Quoted 7 lines
First, as this series shows, is there value in documenting tests which do not require additional configuration? We have some tests with no comments and some that are fully commented, but at the end of the day when trying to run these tests, pytest will already say helpful things like not being supported on a given platform, or not run because something isn't enabled in the build. Spelling that out in generated documentation would require duplication of work.
Yes, I agree. I think the code is the best place for most of the docs.
Quoted 3 lines
Second, is there value in documenting arguments? Especially ones like "ubman" that are just required and always present?
I like documenting arguments, since when people see the docs they continue the trend. Python suffers terribly from a 'def my_function(*args, **kwargs)' disease where you have to spend hours spelunking around to figure out what is actually valid as an argument. Highly Pythonic, but dreadful.
Quoted 5 lines
Third, should we document internal functions too, or just the tests? I would be inclined to say no unless they're expected to be re-used. The
test_netfunctions to bring up the networking are an example that of reuse that should be documented for example.
Sounds right. But I am likely to continue to document all Python functions, since I never know when I'm going to want to export something for use elsewhere.
Regards,
Simon
Re: [PATCH 0/3] doc: Document remaining test_b* tests
Quoted 28 lines · Simon Glass
Hi Tom,
Quoted 13 lines · Tom Rini
Hey all,
This short series is a follow-up to my last series. It could have been longer, but I think this is a good point to get some feedback on a few points.
As background, something I wondered about and the answer seems to be No is, can we automatically take things like:
@pytest.mark.buildconfigspec('cmd_button')
and get some nice output? Since we can't that limits the value, possibly, of generating some documentation.Quoted 7 lines
First, as this series shows, is there value in documenting tests which do not require additional configuration? We have some tests with no comments and some that are fully commented, but at the end of the day when trying to run these tests, pytest will already say helpful things like not being supported on a given platform, or not run because something isn't enabled in the build. Spelling that out in generated documentation would require duplication of work.
Yes, I agree. I think the code is the best place for most of the docs.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Second, is there value in documenting arguments? Especially ones like "ubman" that are just required and always present?
I like documenting arguments, since when people see the docs they continue the trend. Python suffers terribly from a 'def
my_function(*args, **kwargs)' disease where you have to spend hours spelunking around to figure out what is actually valid as an argument. Highly Pythonic, but dreadful.
Maybe I wasn't clear in these two points. Let us use test/py/tests/test_cat.py as a concrete example. Today, most of the file is:
# SPDX-License-Identifier: GPL-2.0+
""" Unit test for cat command
"""
import pytest
from subprocess import call, check_call, CalledProcessError from tests import fs_helper
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_cat')
def test_cat(ubman):
""" Unit test for cat
Args:
ubman -- U-Boot console
"""
try:
....
My point and question is that "@pytest.mark.buildconfigspec('cmd_cat')" will not be translated to generated documentation, but also that if you try and run this test outside of sandbox, pytest already tells you it's not supported, and a similar error if sandbox but not cmd_cat.
So is there any value in adding doc/develop/pytest/test_cat.rst that will consume the above and generate valid documentation that I'm not sure would ever be read?
Quoted 8 lines
Quoted 4 lines
Third, should we document internal functions too, or just the tests? I would be inclined to say no unless they're expected to be re-used. The
test_netfunctions to bring up the networking are an example that of reuse that should be documented for example.Sounds right. But I am likely to continue to document all Python functions, since I never know when I'm going to want to export something for use elsewhere.
I'm certainly not saying we shouldn't comment the code, but perhaps a follow-up to document test/py/tests/test_distro.py would clarify some of what I'm asking about in your mind.
Signature · 1 line
Tom
Re: [PATCH 0/3] doc: Document remaining test_b* tests
Hi Tom,
Quoted 62 lines · Tom Rini
Quoted 28 lines · Simon Glass
Hi Tom,
Quoted 13 lines · Tom Rini
Hey all,
This short series is a follow-up to my last series. It could have been longer, but I think this is a good point to get some feedback on a few points.
As background, something I wondered about and the answer seems to be No is, can we automatically take things like:
@pytest.mark.buildconfigspec('cmd_button')
and get some nice output? Since we can't that limits the value, possibly, of generating some documentation.Quoted 7 lines
First, as this series shows, is there value in documenting tests which do not require additional configuration? We have some tests with no comments and some that are fully commented, but at the end of the day when trying to run these tests, pytest will already say helpful things like not being supported on a given platform, or not run because something isn't enabled in the build. Spelling that out in generated documentation would require duplication of work.
Yes, I agree. I think the code is the best place for most of the docs.
Quoted 1 line
Quoted 8 lines
Quoted 2 lines
Second, is there value in documenting arguments? Especially ones like "ubman" that are just required and always present?
I like documenting arguments, since when people see the docs they continue the trend. Python suffers terribly from a 'def
my_function(*args, **kwargs)' disease where you have to spend hours spelunking around to figure out what is actually valid as an argument. Highly Pythonic, but dreadful.Maybe I wasn't clear in these two points. Let us use
test/py/tests/test_cat.pyas a concrete example. Today, most of the file is:
# SPDX-License-Identifier: GPL-2.0+""" Unit test for cat command
"""import pytest
from subprocess import call,check_call, CalledProcessError from tests importfs_helper@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('cmd_cat')
deftest_cat(ubman):
""" Unit test for catArgs:
ubman -- U-Boot console
"""
try:
....
Quoted 8 lines
My point and question is that "@pytest.mark.buildconfigspec('cmd_cat')" will not be translated to generated documentation, but also that if you try and run this test outside of sandbox, pytest already tells you it's not supported, and a similar error if sandbox but not
cmd_cat.So is there any value in adding
doc/develop/pytest/test_cat.rstthat will consume the above and generate valid documentation that I'm not sure would ever be read?
No, I agree, I don't see any value in that.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Third, should we document internal functions too, or just the tests? I would be inclined to say no unless they're expected to be re-used. The
test_netfunctions to bring up the networking are an example that of reuse that should be documented for example.
Quoted 7 lines
Quoted 3 lines
Sounds right. But I am likely to continue to document all Python functions, since I never know when I'm going to want to export something for use elsewhere.
I'm certainly not saying we shouldn't comment the code, but perhaps a follow-up to document
test/py/tests/test_distro.pywould clarify some of what I'm asking about in your mind.
OK
Regards,
Simon