pytest-requirements 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. pytest_requirements-0.1.0/.gitignore +163 -0
  2. pytest_requirements-0.1.0/.gitlab-ci.yml +125 -0
  3. pytest_requirements-0.1.0/.pre-commit-config.yaml +26 -0
  4. pytest_requirements-0.1.0/CHANGES.rst +6 -0
  5. pytest_requirements-0.1.0/LICENSE +29 -0
  6. pytest_requirements-0.1.0/PKG-INFO +32 -0
  7. pytest_requirements-0.1.0/README.md +7 -0
  8. pytest_requirements-0.1.0/docs/Makefile +23 -0
  9. pytest_requirements-0.1.0/docs/changelog.rst +7 -0
  10. pytest_requirements-0.1.0/docs/changes/README.md +22 -0
  11. pytest_requirements-0.1.0/docs/changes/template.rst +43 -0
  12. pytest_requirements-0.1.0/docs/conf.py +37 -0
  13. pytest_requirements-0.1.0/docs/index.rst +23 -0
  14. pytest_requirements-0.1.0/docs/quickstart.rst +69 -0
  15. pytest_requirements-0.1.0/example_tests/conftest.py +1 -0
  16. pytest_requirements-0.1.0/example_tests/test_requirements.py +31 -0
  17. pytest_requirements-0.1.0/pyproject.toml +147 -0
  18. pytest_requirements-0.1.0/setup.cfg +4 -0
  19. pytest_requirements-0.1.0/sonar-project.properties +9 -0
  20. pytest_requirements-0.1.0/src/pytest_requirements/__init__.py +31 -0
  21. pytest_requirements-0.1.0/src/pytest_requirements/_version.py +16 -0
  22. pytest_requirements-0.1.0/src/pytest_requirements/test_plugin.py +65 -0
  23. pytest_requirements-0.1.0/src/pytest_requirements.egg-info/PKG-INFO +32 -0
  24. pytest_requirements-0.1.0/src/pytest_requirements.egg-info/SOURCES.txt +26 -0
  25. pytest_requirements-0.1.0/src/pytest_requirements.egg-info/dependency_links.txt +1 -0
  26. pytest_requirements-0.1.0/src/pytest_requirements.egg-info/entry_points.txt +2 -0
  27. pytest_requirements-0.1.0/src/pytest_requirements.egg-info/requires.txt +17 -0
  28. pytest_requirements-0.1.0/src/pytest_requirements.egg-info/top_level.txt +1 -0
@@ -0,0 +1,163 @@
1
+ _version.py
2
+ # Byte-compiled / optimized / DLL files
3
+ __pycache__/
4
+ *.py[cod]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ #Pipfile.lock
97
+
98
+ # poetry
99
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103
+ #poetry.lock
104
+
105
+ # pdm
106
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107
+ #pdm.lock
108
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109
+ # in version control.
110
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
111
+ .pdm.toml
112
+ .pdm-python
113
+ .pdm-build/
114
+
115
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116
+ __pypackages__/
117
+
118
+ # Celery stuff
119
+ celerybeat-schedule
120
+ celerybeat.pid
121
+
122
+ # SageMath parsed files
123
+ *.sage.py
124
+
125
+ # Environments
126
+ .env
127
+ .venv
128
+ env/
129
+ venv/
130
+ ENV/
131
+ env.bak/
132
+ venv.bak/
133
+
134
+ # Spyder project settings
135
+ .spyderproject
136
+ .spyproject
137
+
138
+ # Rope project settings
139
+ .ropeproject
140
+
141
+ # mkdocs documentation
142
+ /site
143
+
144
+ # mypy
145
+ .mypy_cache/
146
+ .dmypy.json
147
+ dmypy.json
148
+
149
+ # Pyre type checker
150
+ .pyre/
151
+
152
+ # pytype static type analyzer
153
+ .pytype/
154
+
155
+ # Cython debug symbols
156
+ cython_debug/
157
+
158
+ # PyCharm
159
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
162
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
163
+ #.idea/
@@ -0,0 +1,125 @@
1
+ workflow:
2
+ rules:
3
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
4
+ - if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
5
+ - if: $CI_COMMIT_TAG
6
+
7
+ # jobs in the same stage run in parallel
8
+ # later stages run after all jobs of previous stage were successfull
9
+ stages:
10
+ - static-checks
11
+ - test
12
+ - sonarqube
13
+ - deploy
14
+
15
+ static:
16
+ stage: static-checks
17
+ image: "python:3.10"
18
+
19
+ before_script:
20
+ - apt update && apt install -y --no-install-recommends git
21
+ - python --version
22
+ - pip install pre-commit
23
+
24
+ script:
25
+ - pre-commit run --all-files
26
+
27
+ tests:
28
+ stage: test
29
+ parallel:
30
+ matrix:
31
+ - PYTHON_VERSION:
32
+ - "3.10"
33
+ - "3.11"
34
+ - "3.12"
35
+
36
+ image: "python:$PYTHON_VERSION"
37
+
38
+ before_script:
39
+ - python --version
40
+ - pip install -e .[test]
41
+
42
+ script:
43
+ - pytest -v --color=yes --doctest-modules --doctest-glob='docs/**/*.rst'
44
+
45
+ # Run the coverage on the oldest supported python version
46
+ # no special reason, just to have no "gap" in the versions in the matrix above
47
+ tests-with-cov:
48
+ stage: test
49
+ image: "python:3.9"
50
+
51
+ before_script:
52
+ - python --version
53
+ - pip install -e .[test]
54
+
55
+ script:
56
+ - pytest -v --color=yes --doctest-modules --doctest-glob='docs/**/*.rst' --cov --cov-report=xml
57
+
58
+ artifacts:
59
+ paths:
60
+ - coverage.xml
61
+
62
+ sonarqube:
63
+ stage: sonarqube
64
+ needs:
65
+ - job: tests-with-cov
66
+ artifacts: true
67
+ image:
68
+ name: sonarsource/sonar-scanner-cli:latest
69
+ entrypoint: [""]
70
+
71
+ variables:
72
+ SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
73
+ GIT_DEPTH: "0"
74
+
75
+ script:
76
+ - sonar-scanner -Dsonar.branch.name=${CI_COMMIT_BRANCH}
77
+
78
+ build-docs:
79
+ stage: test
80
+ image: "python:3.12"
81
+
82
+ before_script:
83
+ - python --version
84
+ - pip install .[doc]
85
+
86
+ script:
87
+ - make -C docs html
88
+
89
+ artifacts:
90
+ paths:
91
+ - docs/build/html
92
+
93
+ # actual deployment to gitlab pages, only on main
94
+ pages:
95
+ stage: deploy
96
+ rules:
97
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
98
+ - if: $CI_COMMIT_TAG
99
+ image: "python:3.12"
100
+ needs:
101
+ - job: build-docs
102
+ artifacts: true
103
+ before_script:
104
+ - pip install git+https://gitlab.cta-observatory.org/cta-computing/common/gitlab-multi-version-sphinx/
105
+ script:
106
+ - gitlab_multi_version_sphinx -v
107
+ - find public -maxdepth 1
108
+ artifacts:
109
+ paths:
110
+ - public
111
+ environment: production
112
+
113
+ # Set the TWINE_PASSWORD env variable in the gitlab ci variables
114
+ pypi:
115
+ image: "python:3.12"
116
+ stage: deploy
117
+ rules:
118
+ - if: $CI_COMMIT_TAG
119
+ script:
120
+ - pip install -U twine build
121
+ - python -m build
122
+ - twine upload dist/*
123
+ variables:
124
+ TWINE_NON_INTERACTIVE: "true"
125
+ TWINE_USERNAME: "__token__"
@@ -0,0 +1,26 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0 # Use the ref you want to point at
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ exclude: ".*\\.fits(\\.fz)?"
7
+ - id: check-added-large-files
8
+ - id: check-case-conflict
9
+ - id: check-merge-conflict
10
+ exclude: ".*\\.fits(\\.fz)?"
11
+ - id: end-of-file-fixer
12
+ exclude: ".*\\.fits(\\.fz)?"
13
+
14
+ - repo: https://github.com/codespell-project/codespell
15
+ rev: v2.3.0
16
+ hooks:
17
+ - id: codespell
18
+ additional_dependencies:
19
+ - tomli
20
+
21
+ - repo: https://github.com/astral-sh/ruff-pre-commit
22
+ rev: v0.8.0
23
+ hooks:
24
+ - id: ruff
25
+ args: [ --fix, --show-fixes ]
26
+ - id: ruff-format
@@ -0,0 +1,6 @@
1
+ pytest_requirements 0.1.0 (2024-11-29)
2
+ --------------------------------------
3
+
4
+ Initial release. Supports marking tests using
5
+ ``@pytest.mark.verifies_requirement("<ID>")`` and ``@pytest.mark.verifies_usecase("<ID>")``
6
+ as well as exporting the marker information to the junit xml file.
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, Cherenkov Telescope Array Observatory
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.1
2
+ Name: pytest-requirements
3
+ Version: 0.1.0
4
+ Summary: pytest plugin for using custom markers to relate tests to requirements and usecases
5
+ Author-email: Maximilian Linhoff <maximilian.linhoff@tu-dortmund.de>
6
+ License: BSD-3-Clause
7
+ Project-URL: repository, https://gitlab.cta-observatory.org/cta-computing/common/pytest-requirements
8
+ Project-URL: documentation, http://cta-computing.gitlab-pages.cta-observatory.org/common/pytest-requirements
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: pytest
13
+ Provides-Extra: test
14
+ Requires-Dist: pytest-cov; extra == "test"
15
+ Provides-Extra: doc
16
+ Requires-Dist: sphinx; extra == "doc"
17
+ Requires-Dist: numpydoc; extra == "doc"
18
+ Requires-Dist: ctao-sphinx-theme~=0.1.2; extra == "doc"
19
+ Requires-Dist: sphinx-changelog; extra == "doc"
20
+ Provides-Extra: dev
21
+ Requires-Dist: setuptools_scm; extra == "dev"
22
+ Requires-Dist: towncrier; extra == "dev"
23
+ Provides-Extra: all
24
+ Requires-Dist: pytest-requirements[dev,doc,test]; extra == "all"
25
+
26
+ # pytest-requirements
27
+
28
+
29
+ pytest plugin providing markers to link tests to requirements and usecases.
30
+
31
+
32
+ Please see the [quickstart documentation](http://cta-computing.gitlab-pages.cta-observatory.org/common/pytest-requirements/latest/quickstart.html) to get started.
@@ -0,0 +1,7 @@
1
+ # pytest-requirements
2
+
3
+
4
+ pytest plugin providing markers to link tests to requirements and usecases.
5
+
6
+
7
+ Please see the [quickstart documentation](http://cta-computing.gitlab-pages.cta-observatory.org/common/pytest-requirements/latest/quickstart.html) to get started.
@@ -0,0 +1,23 @@
1
+ # Minimal makefile for Sphinx documentation
2
+
3
+ # You can set these variables from the command line, and also
4
+ # from the environment for the first two.
5
+ SPHINXOPTS ?= -W --keep-going -n --color
6
+ SPHINXBUILD ?= sphinx-build
7
+ SOURCEDIR = .
8
+ BUILDDIR = build
9
+
10
+ # Put it first so that "make" without argument is like "make help".
11
+ help:
12
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13
+
14
+ .PHONY: help Makefile clean
15
+
16
+ # Catch-all target: route all unknown targets to Sphinx using the new
17
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
18
+ %: Makefile
19
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20
+
21
+ clean:
22
+ rm -rf docs/api
23
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@@ -0,0 +1,7 @@
1
+ Change Log
2
+ ==========
3
+
4
+ .. changelog::
5
+ :towncrier: ../
6
+ :towncrier-skip-if-empty:
7
+ :changelog_file: ../CHANGES.rst
@@ -0,0 +1,22 @@
1
+ # How to use towncrier
2
+
3
+ An overview can be found [here](https://towncrier.readthedocs.io/en/stable/quickstart.html#).
4
+
5
+ 1. Create a new file for your changes `<MERGE REQUEST NUMBER>.<TYPE>.rst` in the corresponding folder.
6
+ The following types are available:
7
+ - feature: `New feature`
8
+ - bugfix: `Bugfix`
9
+ - api: `API Changes`
10
+ - optimization: `Refactoring and Optimization`
11
+ - maintenance: `Maintenance`
12
+
13
+ 2. Write a suitable message for the change:
14
+ ```
15
+ Fixed ``crazy_function`` to be consistent with ``not_so_crazy_function``
16
+ ```
17
+
18
+ 3. (For maintainers) How to generate a change log:
19
+ Execute the following command in the base directory of the project
20
+ ```
21
+ towncrier build --version=<VERSION NUMBER>
22
+ ```
@@ -0,0 +1,43 @@
1
+ {% if render_title %}
2
+ {% if versiondata.name %}
3
+ {{ versiondata.name | lower }} {{ versiondata.version }} ({{ versiondata.date }})
4
+ {{ top_underline * ((versiondata.name + versiondata.version + versiondata.date)|length + 4)}}
5
+ {% else %}
6
+ {{ versiondata.version }} ({{ versiondata.date }})
7
+ {{ top_underline * ((versiondata.version + versiondata.date)|length + 3)}}
8
+ {% endif %}
9
+ {% endif %}
10
+
11
+ {% for category, val in definitions.items() %}
12
+
13
+ {% set underline = underlines[0] %}
14
+ {{ definitions[category]['name'] }}
15
+ {{ underline * definitions[category]['name']|length }}
16
+ {% set underline = underlines[1] %}
17
+
18
+ {% for section, _ in sections.items() %}
19
+ {% if section and category in sections[section] %}
20
+ {{section}}
21
+ {{ underline * section|length }}
22
+
23
+ {% endif %}
24
+ {% if sections[section] and category in sections[section] %}
25
+ {% if definitions[category]['showcontent'] %}
26
+ {% for text, values in sections[section][category].items() %}
27
+ - {{ text }} [{{ values|join(', ') }}]
28
+
29
+ {% endfor %}
30
+ {% else %}
31
+ - {{ sections[section][category]['']|join(', ') }}
32
+
33
+ {% endif %}
34
+ {% if sections[section][category]|length == 0 %}
35
+ No significant changes.
36
+
37
+ {% else %}
38
+ {% endif %}
39
+ {% else %}
40
+ {# No significant changes. #}
41
+ {% endif %}
42
+ {% endfor %}
43
+ {% endfor %}
@@ -0,0 +1,37 @@
1
+ import pytest_requirements
2
+
3
+ project = "pytest_requirements"
4
+ copyright = "CTAO"
5
+ author = "CTAO Computing Department"
6
+ version = pytest_requirements.__version__
7
+ # The full version, including alpha/beta/rc tags.
8
+ release = version
9
+
10
+
11
+ extensions = [
12
+ "sphinx.ext.intersphinx",
13
+ "sphinx.ext.autodoc",
14
+ "sphinx.ext.autosummary",
15
+ "numpydoc",
16
+ "sphinx_changelog",
17
+ ]
18
+
19
+ exclude_patterns = ["changes"]
20
+ default_role = "py:obj"
21
+
22
+ intersphinx_mapping = {
23
+ "python": ("https://docs.python.org/3/", None),
24
+ "pytest": ("https://docs.pytest.org/en/stable/", None),
25
+ }
26
+
27
+ html_theme = "ctao"
28
+ html_theme_options = dict(
29
+ navigation_with_keys=False,
30
+ switcher=dict(
31
+ json_url="http://cta-computing.gitlab-pages.cta-observatory.org/common/pytest-requirements/versions.json", # noqa: E501
32
+ version_match="latest" if ".dev" in version else f"v{version}",
33
+ ),
34
+ navbar_center=["version-switcher", "navbar-nav"],
35
+ )
36
+
37
+ html_static_path = []
@@ -0,0 +1,23 @@
1
+ pytest-requirements
2
+ ===================
3
+
4
+ Plugin to help with requirement and usecase verification using pytest.
5
+
6
+ **Version**: |version| **Date**: |today|
7
+
8
+
9
+ .. toctree::
10
+ :maxdepth: 1
11
+ :caption: Contents:
12
+
13
+ quickstart
14
+ changelog
15
+
16
+
17
+
18
+ Indices and tables
19
+ ------------------
20
+
21
+ * :ref:`genindex`
22
+ * :ref:`modindex`
23
+ * :ref:`search`
@@ -0,0 +1,69 @@
1
+ Quickstart
2
+ ==========
3
+
4
+ This project defines two pytest markers that allow linking of
5
+ tests to requirement and usecase IDs.
6
+
7
+
8
+ Installation and Setup
9
+ ----------------------
10
+
11
+ To use this plugin, add it to your test dependencies, e.g. like this:
12
+
13
+ .. code-block:: toml
14
+ :caption: ``pyproject.toml``
15
+ :emphasize-lines: 4
16
+
17
+ [project.optional-dependencies]
18
+ test = [
19
+ "pytest",
20
+ "pytest-requirements",
21
+ "pytest-cov",
22
+ ]
23
+
24
+ And enable the plugin via the ``addopts`` configuration option:
25
+
26
+ .. code-block:: toml
27
+ :caption: ``pyproject.toml``
28
+ :emphasize-lines: 4
29
+
30
+ [tool.pytest.ini_options]
31
+ minversion = "7"
32
+ testpaths = ["src"]
33
+ addopts = ["-p", "pytest_requirements"]
34
+
35
+
36
+ Linking tests to requirements and usecases
37
+ ------------------------------------------
38
+
39
+ Then you can use two markers to connect your tests to usecases and requirements:
40
+
41
+ .. code-block:: python
42
+
43
+ import pytest
44
+
45
+ @pytest.mark.verifies_requirement("B-DPPS-0123")
46
+ def test_super_important_requirement():
47
+ pass
48
+
49
+
50
+ @pytest.mark.verifies_usecase("UC-130-2.1")
51
+ def test_super_important_usecase():
52
+ pass
53
+
54
+
55
+ Generating XML reports
56
+ ----------------------
57
+
58
+ The requirement and usecase IDs are also included in the ``junit``-style xml reports:
59
+
60
+ .. code-block:: shell
61
+
62
+ $ pytest --junit-xml=report.xml
63
+
64
+ ``report.xml`` will contain properties for in each ``<testcase>``-node of the form:
65
+
66
+ .. code-block:: xml
67
+
68
+ <property name="requirement_id" value="B-DPPS-0123" />
69
+ <property name="usecase_id" value="UC-123-2.1" />
@@ -0,0 +1 @@
1
+ pytest_plugins = ["pytest_requirements"]
@@ -0,0 +1,31 @@
1
+ import pytest
2
+
3
+
4
+ @pytest.mark.verifies_requirement("B-DPPS-0123")
5
+ def test_single_requirement():
6
+ pass
7
+
8
+
9
+ @pytest.mark.verifies_requirement("B-DPPS-0123")
10
+ @pytest.mark.verifies_requirement("B-DPPS-0124")
11
+ @pytest.mark.verifies_requirement("B-DPPS-0125")
12
+ def test_multiple_requirements():
13
+ pass
14
+
15
+
16
+ @pytest.mark.verifies_usecase("UC-130-1.2")
17
+ def test_usecase():
18
+ pass
19
+
20
+
21
+ @pytest.mark.verifies_usecase("UC-130-1.2.1")
22
+ @pytest.mark.verifies_usecase("UC-130-1.2.2")
23
+ def test_multiple_usecases():
24
+ pass
25
+
26
+
27
+ @pytest.mark.verifies_usecase("UC-130-1.2.1")
28
+ @pytest.mark.verifies_usecase("UC-130-1.2.2")
29
+ @pytest.mark.verifies_requirement("B-DPPS-0123")
30
+ def test_mixed():
31
+ pass
@@ -0,0 +1,147 @@
1
+ [build-system]
2
+ requires = ["setuptools>=65", "setuptools_scm[toml]>=8"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pytest-requirements"
7
+ description = "pytest plugin for using custom markers to relate tests to requirements and usecases"
8
+ readme = "README.md"
9
+ license = {text = "BSD-3-Clause"}
10
+ authors = [
11
+ {name = "Maximilian Linhoff", email = "maximilian.linhoff@tu-dortmund.de"},
12
+ ]
13
+
14
+ requires-python = ">=3.9"
15
+ dependencies = [
16
+ "pytest",
17
+ ]
18
+
19
+ # needed for setuptools_scm, we don"t define a static version
20
+ dynamic = ["version"]
21
+
22
+ [project.urls]
23
+ repository = "https://gitlab.cta-observatory.org/cta-computing/common/pytest-requirements"
24
+ documentation = "http://cta-computing.gitlab-pages.cta-observatory.org/common/pytest-requirements"
25
+
26
+ [tool.setuptools.packages.find]
27
+ where = ["src"]
28
+
29
+ [project.optional-dependencies]
30
+ test = [
31
+ "pytest-cov",
32
+ ]
33
+ doc = [
34
+ "sphinx",
35
+ "numpydoc",
36
+ "ctao-sphinx-theme~=0.1.2",
37
+ "sphinx-changelog",
38
+ ]
39
+ dev = [
40
+ "setuptools_scm",
41
+ "towncrier",
42
+ ]
43
+
44
+ # we can use self-references to simplify all, needs to match project.name defined above
45
+ all = [
46
+ "pytest-requirements[test,doc,dev]",
47
+ ]
48
+
49
+ [tool.setuptools_scm]
50
+ write_to = "src/pytest_requirements/_version.py"
51
+
52
+ [project.entry-points.pytest11]
53
+ pytest_requirements = "pytest_requirements"
54
+
55
+
56
+ [tool.towncrier]
57
+ package = "pytest_requirements"
58
+ directory = "docs/changes"
59
+ filename = "CHANGES.rst"
60
+ template = "docs/changes/template.rst"
61
+ underlines = ["-", "~", "^"]
62
+ # Let towncrier create proper links to the merged MR.
63
+ # By default, towncrier connects everything to issues.
64
+ # We rather want to connect it to merge request
65
+ issue_format = "`!{issue} <https://gitlab.cta-observatory.org/cta-computing/common/pytest-requirements/-/merge_requests/{issue}>`__"
66
+
67
+ [tool.towncrier.fragment.feature]
68
+ name = "New Features"
69
+ showcontent = true
70
+
71
+ [tool.towncrier.fragment.bugfix]
72
+ name = "Bug Fixes"
73
+ showcontent = true
74
+
75
+ [tool.towncrier.fragment.api]
76
+ name = "API Changes"
77
+ showcontent = true
78
+
79
+ [tool.towncrier.fragment.optimization]
80
+ name = "Refactoring and Optimization"
81
+ showcontent = true
82
+
83
+ [tool.towncrier.fragment.maintenance]
84
+ name = "Maintenance"
85
+ showcontent = true
86
+
87
+ [tool.ruff]
88
+ line-length = 88
89
+ target-version = "py39"
90
+
91
+
92
+ [tool.ruff.lint]
93
+ extend-select = [
94
+ "I", # isort
95
+ "N", # pep8 naming
96
+ "D", # pydocstyle
97
+ "PT", # pytest
98
+ "UP", # pyupgrade
99
+ "COM", # flake8-commas
100
+ "ISC", # implicit string concat rules
101
+ "ICN", # import name conventions
102
+ "G", # logging
103
+ ]
104
+ ignore = [
105
+ "COM812", # incompatible with ruff format
106
+ "ISC001", # incompatible with ruff format
107
+ ]
108
+
109
+ [tool.ruff.lint.pydocstyle]
110
+ convention = "numpy"
111
+
112
+ [tool.ruff.lint.per-file-ignores]
113
+ # no documentation linting for test files
114
+ "**/tests/**" = ["D"]
115
+ "**/test_*.py" = ["D"]
116
+ "**/conftest.py" = ["D"]
117
+ "example_tests/**.py" = ["D"]
118
+ "docs/**/*.py" = ["D"]
119
+
120
+ [tool.ruff.format]
121
+ quote-style = "double"
122
+ indent-style = "space"
123
+ skip-magic-trailing-comma = false
124
+ line-ending = "auto"
125
+
126
+ [tool.isort]
127
+ profile = "black"
128
+ line_length = 88
129
+
130
+ [tool.coverage.run]
131
+ relative_files = true
132
+ source = ["src"]
133
+ omit = [
134
+ "src/pytest_requirements/_version.py",
135
+ ]
136
+
137
+ [tool.pytest.ini_options]
138
+ minversion = "7"
139
+ testpaths = ["src"]
140
+ log_cli_level = "INFO"
141
+ xfail_strict = true
142
+ # print summary of failed tests, force errors if settings are misspelled
143
+ addopts = ["-p", "pytester", "-ra", "--strict-config", "--strict-markers"]
144
+ filterwarnings = [
145
+ "error",
146
+ ]
147
+ pytester_example_dir = "example_tests"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,9 @@
1
+ sonar.projectKey=cta-computing_common_pytest-requirements_AZN0FJNnAfB1AuE28RjL
2
+ sonar.host.url=https://sonar-cta-dpps.zeuthen.desy.de
3
+ sonar.qualitygate.wait=true
4
+ sonar.language=python
5
+ sonar.python.coverage.reportPaths=coverage.xml
6
+ sonar.python.version=3
7
+
8
+ # ignore some files not relevant for testing so they don't count towards missing coverage
9
+ sonar.exclusions=src/pytest_requirements/version.py,docs/conf.py,example_tests/**
@@ -0,0 +1,31 @@
1
+ """pytest plugin providing markers to link tests to requirements and usecases."""
2
+
3
+ from ._version import __version__
4
+
5
+
6
+ def pytest_configure(config):
7
+ """Register our custom markers."""
8
+ config.addinivalue_line(
9
+ "markers",
10
+ "verifies_requirement(requirement_id): Mark this test as verification for a requirement",
11
+ )
12
+ config.addinivalue_line(
13
+ "markers",
14
+ "verifies_usecase(usecase_id): Mark this test as verification for a usecase",
15
+ )
16
+
17
+
18
+ def pytest_collection_modifyitems(session, config, items):
19
+ """Customize test collection.
20
+
21
+ - Make sure requirement/usecase marker information is written to junit xml.
22
+ """
23
+ for item in items:
24
+ for type_ in ("requirement", "usecase"):
25
+ for marker in item.iter_markers(name=f"verifies_{type_}"):
26
+ item.user_properties.append((f"{type_}_id", marker.args[0]))
27
+
28
+
29
+ __all__ = [
30
+ "__version__",
31
+ ]
@@ -0,0 +1,16 @@
1
+ # file generated by setuptools_scm
2
+ # don't change, don't track in version control
3
+ TYPE_CHECKING = False
4
+ if TYPE_CHECKING:
5
+ from typing import Tuple, Union
6
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
7
+ else:
8
+ VERSION_TUPLE = object
9
+
10
+ version: str
11
+ __version__: str
12
+ __version_tuple__: VERSION_TUPLE
13
+ version_tuple: VERSION_TUPLE
14
+
15
+ __version__ = version = '0.1.0'
16
+ __version_tuple__ = version_tuple = (0, 1, 0)
@@ -0,0 +1,65 @@
1
+ from xml.etree import ElementTree as ET
2
+
3
+ EXPECTED = {
4
+ "test_single_requirement": {
5
+ "requirements": ["B-DPPS-0123"],
6
+ "usecases": [],
7
+ },
8
+ "test_multiple_requirements": {
9
+ "requirements": ["B-DPPS-0123", "B-DPPS-0124", "B-DPPS-0125"],
10
+ "usecases": [],
11
+ },
12
+ "test_usecase": {
13
+ "requirements": [],
14
+ "usecases": ["UC-130-1.2"],
15
+ },
16
+ "test_multiple_usecases": {
17
+ "requirements": [],
18
+ "usecases": ["UC-130-1.2.1", "UC-130-1.2.2"],
19
+ },
20
+ "test_mixed": {
21
+ "requirements": ["B-DPPS-0123"],
22
+ "usecases": ["UC-130-1.2.1", "UC-130-1.2.2"],
23
+ },
24
+ }
25
+
26
+
27
+ def collect_markers(test_case):
28
+ markers = {"requirements": [], "usecases": []}
29
+ for prop in test_case.iter("property"):
30
+ if prop.attrib["name"] == "requirement_id":
31
+ markers["requirements"].append(prop.attrib["value"])
32
+ elif prop.attrib["name"] == "usecase_id":
33
+ markers["usecases"].append(prop.attrib["value"])
34
+ return markers
35
+
36
+
37
+ def test_plugin(pytester, tmp_path):
38
+ pytester.copy_example("conftest.py")
39
+ pytester.copy_example("test_requirements.py")
40
+
41
+ report_path = tmp_path / "report.xml"
42
+ result = pytester.runpytest(f"--junit-xml={report_path}")
43
+
44
+ result.assert_outcomes(passed=5)
45
+
46
+ # make sure the marker information is in the junit xml
47
+ tree = ET.parse(report_path)
48
+
49
+ test_cases = {
50
+ test_case.attrib["name"]: test_case for test_case in tree.iter("testcase")
51
+ }
52
+ assert len(test_cases) == 5
53
+
54
+ for key, expected in EXPECTED.items():
55
+ markers = collect_markers(test_cases[key])
56
+ for type_, expected_ids in expected.items():
57
+ ids = markers[type_]
58
+ assert len(ids) == len(expected_ids)
59
+ assert set(ids) == set(expected_ids)
60
+
61
+
62
+ def test_version():
63
+ from pytest_requirements import __version__
64
+
65
+ assert __version__ != "0.0.0"
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.1
2
+ Name: pytest-requirements
3
+ Version: 0.1.0
4
+ Summary: pytest plugin for using custom markers to relate tests to requirements and usecases
5
+ Author-email: Maximilian Linhoff <maximilian.linhoff@tu-dortmund.de>
6
+ License: BSD-3-Clause
7
+ Project-URL: repository, https://gitlab.cta-observatory.org/cta-computing/common/pytest-requirements
8
+ Project-URL: documentation, http://cta-computing.gitlab-pages.cta-observatory.org/common/pytest-requirements
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: pytest
13
+ Provides-Extra: test
14
+ Requires-Dist: pytest-cov; extra == "test"
15
+ Provides-Extra: doc
16
+ Requires-Dist: sphinx; extra == "doc"
17
+ Requires-Dist: numpydoc; extra == "doc"
18
+ Requires-Dist: ctao-sphinx-theme~=0.1.2; extra == "doc"
19
+ Requires-Dist: sphinx-changelog; extra == "doc"
20
+ Provides-Extra: dev
21
+ Requires-Dist: setuptools_scm; extra == "dev"
22
+ Requires-Dist: towncrier; extra == "dev"
23
+ Provides-Extra: all
24
+ Requires-Dist: pytest-requirements[dev,doc,test]; extra == "all"
25
+
26
+ # pytest-requirements
27
+
28
+
29
+ pytest plugin providing markers to link tests to requirements and usecases.
30
+
31
+
32
+ Please see the [quickstart documentation](http://cta-computing.gitlab-pages.cta-observatory.org/common/pytest-requirements/latest/quickstart.html) to get started.
@@ -0,0 +1,26 @@
1
+ .gitignore
2
+ .gitlab-ci.yml
3
+ .pre-commit-config.yaml
4
+ CHANGES.rst
5
+ LICENSE
6
+ README.md
7
+ pyproject.toml
8
+ sonar-project.properties
9
+ docs/Makefile
10
+ docs/changelog.rst
11
+ docs/conf.py
12
+ docs/index.rst
13
+ docs/quickstart.rst
14
+ docs/changes/README.md
15
+ docs/changes/template.rst
16
+ example_tests/conftest.py
17
+ example_tests/test_requirements.py
18
+ src/pytest_requirements/__init__.py
19
+ src/pytest_requirements/_version.py
20
+ src/pytest_requirements/test_plugin.py
21
+ src/pytest_requirements.egg-info/PKG-INFO
22
+ src/pytest_requirements.egg-info/SOURCES.txt
23
+ src/pytest_requirements.egg-info/dependency_links.txt
24
+ src/pytest_requirements.egg-info/entry_points.txt
25
+ src/pytest_requirements.egg-info/requires.txt
26
+ src/pytest_requirements.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [pytest11]
2
+ pytest_requirements = pytest_requirements
@@ -0,0 +1,17 @@
1
+ pytest
2
+
3
+ [all]
4
+ pytest-requirements[dev,doc,test]
5
+
6
+ [dev]
7
+ setuptools_scm
8
+ towncrier
9
+
10
+ [doc]
11
+ sphinx
12
+ numpydoc
13
+ ctao-sphinx-theme~=0.1.2
14
+ sphinx-changelog
15
+
16
+ [test]
17
+ pytest-cov
@@ -0,0 +1 @@
1
+ pytest_requirements