Name | thinking-tests JSON |
Version |
0.0.4
JSON |
| download |
home_page | None |
Summary | Declarative API over unittest with customizable auto-discovery, test lifecycle and handy integrations |
upload_time | 2024-09-03 22:52:32 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.12 |
license | MIT License Copyright (c) 2024 Filip Malczak Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
thinking
test
unittest
junit
report
coverage
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# thinking-tests
[![CI](https://github.com/FilipMalczak/thinking-tests/actions/workflows/ci.yml/badge.svg)](https://github.com/FilipMalczak/thinking-tests/actions/workflows/ci.yml)
[![PyPI version](https://badge.fury.io/py/thinking-tests.svg)](https://badge.fury.io/py/thinking-tests)
> Part of [thinking](https://github.com/search?q=owner%3AFilipMalczak+thinking&type=repositories) family.
Declarative API over unittest with customizable auto-discovery and test lifecycle.
> Requires python 3.12. Is mostly typed.
What started as fluent, decorator-based API over `unittest`, grew into a facade that uses `unittest` as testing
backend, while providing bunch of report and integrating coverage too.
Is heavily based on `thinking` framework pieces, so you better get acquainted with [`thinking-runtime`](https://github.com/FilipMalczak/thinking-runtime).
## Usage
### Declaring tests
Put your tests into package lying in repository root. This assumption is important for discovery, but also a good practice.
For this part you need [`decorators` module](./thinking_tests/decorators.py):
```python
from thinking_tests.decorators import case, setup, teardown
```
You declare test cases with decorator:
```python
@case
def my_case():
assert 1 + 1 == 2
```
You can tweak setup and teardown with context managers:
```python
def my_setup():
...
def my_teardown():
...
with setup(my_setup), teardown(my_teardown):
@case
def my_case():
...
```
## Running tests
Use the `__name__ == "__main__"` idiom and `run_(all|current_(module|package))()` functions (from
[`thinking_tests.running.start` module](./thinking_tests/running/start.py)).
- `run_all()` will scan the current root package for test cases and run them all
- if you call that function from `pkg.subpkg.module`, it will scan every module (at any depth) in `pkg` package
- `run_current_package()` will do similar thing, but will run all the tests in the same package (and lower) as from
where you call it
- e.g. if you have tests in `pkg.sub.sub1.mod` and `pkg.sub.sub2.mod` and call it from `pkg.sub.run`, it will pick up
both these modules, but not cases defined in `pkg.another.mod`
- `run_current_module()` will only run cases defined in the module where it is called
See [`test_fixture`](./test_fixture) for an example usage - `x` and `y` modules will use `if __name__=="__main__": run_current_module()`,
while `run_all` will have `if __name__=="__main__": run_all()`. That way you can have `x` and `y` suites, while being
able to run all available tests with `python -m test_fixture.run_all`.
## Reporting
`thinking-tests` come with JUnit XML and HTML reports, Coverage data files, XML reports and HTML reports out of the box.
By default all of them are enabled. Tha way you're set up for CI (which may consume unittest XML report and Coverage
binary/XML report) as well as local development (where you probably wanna see report in nice, webbrowser-based UI).
> Great kudos to [vjunit](https://github.com/ahsayde/vjunit) and [junit_xml](https://github.com/kyrus/python-junit-xml)
> authors, from which I stole the code before tweaking it for smoother experience.
### Configuration
As mentioned, configuration is based on [`thinking-runtime`](https://github.com/FilipMalczak/thinking-runtime) bootstrapping
mechanism. You can define your own `__test__`/`__tests__`/`__testing__` config file, where you interact with
[`thinking_tests.running.test_config.test_config`](./thinking_tests/running/test_config.py) object.
It has 2 properties:
- `unittest`
- exposes 2 `str` properties:
- `xml_report_path`
- `html_report_path`
- both of them are resolved against repository root, if they are not `None` and are not absolute paths
- if they are `None`, appropriate report is turned off
- if XML report is disabled, HTML report must be disabled, or it will be an error
- there are also `(xml|html)_report_enabled` and simply `enabled` properties
- they have getters
- they also have setters, but if you pass `True`, it will be an error - use them only to quickly turn off appropriate
report
- `(...).enabled = False` will set `None` to both paths
- `coverage`
- exposes 3 `str` properties:
- `binary_report_path` - being the Coverage SQLite data file path
- `xml_report_path`
- `html_report_dir` - notice that it points to a directory, not a single file
- they are also resolved against repo root, same as with `unittest`, and they are interpreted in the same fashion
when they are `None`
- binary report must be enabled for other reports to be enabled, or you'll get an error
- you'll also find `(binary|xml|html)_report_enabled` and just `enabled` properties that behave similarly as with `unittest`
- there are also properties passed directly [to Coverage](https://coverage.readthedocs.io/en/7.6.1/api_coverage.html#coverage.Coverage)
- they are:
- `branch: Optional[bool]`
- 'include: Optional[str | Iterable[str]]'
- 'omit: Optional[str | Iterable[str]]'
- they must be `None` (default) if binary report is disabled
Raw data
{
"_id": null,
"home_page": null,
"name": "thinking-tests",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "thinking, test, unittest, junit, report, coverage",
"author": null,
"author_email": "Filip Malczak <filip.malczak@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/5f/dd/6916b071aea3fbd14b0b4be1e10cb7979049016beb4944ac4608bdcb21b5/thinking_tests-0.0.4.tar.gz",
"platform": null,
"description": "# thinking-tests\n\n[![CI](https://github.com/FilipMalczak/thinking-tests/actions/workflows/ci.yml/badge.svg)](https://github.com/FilipMalczak/thinking-tests/actions/workflows/ci.yml)\n[![PyPI version](https://badge.fury.io/py/thinking-tests.svg)](https://badge.fury.io/py/thinking-tests)\n\n> Part of [thinking](https://github.com/search?q=owner%3AFilipMalczak+thinking&type=repositories) family.\n\nDeclarative API over unittest with customizable auto-discovery and test lifecycle.\n\n> Requires python 3.12. Is mostly typed.\n\nWhat started as fluent, decorator-based API over `unittest`, grew into a facade that uses `unittest` as testing\nbackend, while providing bunch of report and integrating coverage too.\n\nIs heavily based on `thinking` framework pieces, so you better get acquainted with [`thinking-runtime`](https://github.com/FilipMalczak/thinking-runtime).\n\n## Usage\n\n### Declaring tests\n\nPut your tests into package lying in repository root. This assumption is important for discovery, but also a good practice.\n\nFor this part you need [`decorators` module](./thinking_tests/decorators.py):\n\n```python\nfrom thinking_tests.decorators import case, setup, teardown\n```\n\nYou declare test cases with decorator:\n\n```python\n@case\ndef my_case():\n assert 1 + 1 == 2 \n```\n\nYou can tweak setup and teardown with context managers:\n\n```python\ndef my_setup():\n ...\n\ndef my_teardown():\n ...\n\nwith setup(my_setup), teardown(my_teardown):\n @case\n def my_case():\n ...\n```\n\n## Running tests\n\nUse the `__name__ == \"__main__\"` idiom and `run_(all|current_(module|package))()` functions (from \n[`thinking_tests.running.start` module](./thinking_tests/running/start.py)).\n\n - `run_all()` will scan the current root package for test cases and run them all\n - if you call that function from `pkg.subpkg.module`, it will scan every module (at any depth) in `pkg` package\n - `run_current_package()` will do similar thing, but will run all the tests in the same package (and lower) as from\n where you call it\n - e.g. if you have tests in `pkg.sub.sub1.mod` and `pkg.sub.sub2.mod` and call it from `pkg.sub.run`, it will pick up\n both these modules, but not cases defined in `pkg.another.mod`\n - `run_current_module()` will only run cases defined in the module where it is called\n\nSee [`test_fixture`](./test_fixture) for an example usage - `x` and `y` modules will use `if __name__==\"__main__\": run_current_module()`,\nwhile `run_all` will have `if __name__==\"__main__\": run_all()`. That way you can have `x` and `y` suites, while being\nable to run all available tests with `python -m test_fixture.run_all`.\n\n## Reporting\n\n`thinking-tests` come with JUnit XML and HTML reports, Coverage data files, XML reports and HTML reports out of the box.\n\nBy default all of them are enabled. Tha way you're set up for CI (which may consume unittest XML report and Coverage \nbinary/XML report) as well as local development (where you probably wanna see report in nice, webbrowser-based UI).\n\n> Great kudos to [vjunit](https://github.com/ahsayde/vjunit) and [junit_xml](https://github.com/kyrus/python-junit-xml)\n> authors, from which I stole the code before tweaking it for smoother experience.\n\n### Configuration\n\nAs mentioned, configuration is based on [`thinking-runtime`](https://github.com/FilipMalczak/thinking-runtime) bootstrapping\nmechanism. You can define your own `__test__`/`__tests__`/`__testing__` config file, where you interact with\n[`thinking_tests.running.test_config.test_config`](./thinking_tests/running/test_config.py) object.\n\nIt has 2 properties:\n\n - `unittest`\n - exposes 2 `str` properties:\n - `xml_report_path`\n - `html_report_path`\n - both of them are resolved against repository root, if they are not `None` and are not absolute paths\n - if they are `None`, appropriate report is turned off\n - if XML report is disabled, HTML report must be disabled, or it will be an error\n - there are also `(xml|html)_report_enabled` and simply `enabled` properties\n - they have getters\n - they also have setters, but if you pass `True`, it will be an error - use them only to quickly turn off appropriate\n report\n - `(...).enabled = False` will set `None` to both paths\n - `coverage`\n - exposes 3 `str` properties:\n - `binary_report_path` - being the Coverage SQLite data file path\n - `xml_report_path`\n - `html_report_dir` - notice that it points to a directory, not a single file\n - they are also resolved against repo root, same as with `unittest`, and they are interpreted in the same fashion \n when they are `None`\n - binary report must be enabled for other reports to be enabled, or you'll get an error\n - you'll also find `(binary|xml|html)_report_enabled` and just `enabled` properties that behave similarly as with `unittest`\n - there are also properties passed directly [to Coverage](https://coverage.readthedocs.io/en/7.6.1/api_coverage.html#coverage.Coverage)\n - they are:\n - `branch: Optional[bool]`\n - 'include: Optional[str | Iterable[str]]'\n - 'omit: Optional[str | Iterable[str]]'\n - they must be `None` (default) if binary report is disabled\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Filip Malczak Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Declarative API over unittest with customizable auto-discovery, test lifecycle and handy integrations",
"version": "0.0.4",
"project_urls": {
"Homepage": "https://github.com/FilipMalczak/thinking-tests"
},
"split_keywords": [
"thinking",
" test",
" unittest",
" junit",
" report",
" coverage"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "95a83433d44f731880f007c88ef33eda01b37b26ce97fba5f6351f66d1642c82",
"md5": "e126e8093a2ce90224be0b29e8883cbb",
"sha256": "c0b6e4f03641c590a63e3dee00ce363b371e42a659b486cdc618605c81cce518"
},
"downloads": -1,
"filename": "thinking_tests-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e126e8093a2ce90224be0b29e8883cbb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 30435,
"upload_time": "2024-09-03T22:52:31",
"upload_time_iso_8601": "2024-09-03T22:52:31.615212Z",
"url": "https://files.pythonhosted.org/packages/95/a8/3433d44f731880f007c88ef33eda01b37b26ce97fba5f6351f66d1642c82/thinking_tests-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5fdd6916b071aea3fbd14b0b4be1e10cb7979049016beb4944ac4608bdcb21b5",
"md5": "7c0d206af89b6a6ed5e3c80aa15d6e6d",
"sha256": "686f7fc3ee93c8995c15a87aa82ddcdf531866a5855969b189e96b5570193950"
},
"downloads": -1,
"filename": "thinking_tests-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "7c0d206af89b6a6ed5e3c80aa15d6e6d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 28114,
"upload_time": "2024-09-03T22:52:32",
"upload_time_iso_8601": "2024-09-03T22:52:32.865095Z",
"url": "https://files.pythonhosted.org/packages/5f/dd/6916b071aea3fbd14b0b4be1e10cb7979049016beb4944ac4608bdcb21b5/thinking_tests-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-03 22:52:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "FilipMalczak",
"github_project": "thinking-tests",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "thinking-tests"
}