Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allenrobel/pytest-toi
Example code and pytest test cases to test the code.
https://github.com/allenrobel/pytest-toi
Last synced: 16 days ago
JSON representation
Example code and pytest test cases to test the code.
- Host: GitHub
- URL: https://github.com/allenrobel/pytest-toi
- Owner: allenrobel
- Created: 2024-01-31T05:43:52.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-01-31T17:34:34.000Z (11 months ago)
- Last Synced: 2024-12-15T09:05:38.586Z (19 days ago)
- Language: Python
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Example pytest testcases and some code to test.
To use:
1. Install pytest if not already installed.
```bash
pip install pytest
```2. Clone the repo.
```bash
git clone https://github.com/allenrobel/pytest-toi.git
```2. cd into the local clone.
```bash
cd pytest-toi
```3. Run the testcases
```bash
pytest
```4. To run a specific test case:
```bash
pytest -k test_monkeypatch_baz
```## Coverage report
1. Have a look in the coverage.bash script for details on how to use it to generate a coverage report for the example code in this repo.
2. Run coverage.bash (modify as needed depending on your local repo path)
From the report, you should see that:
1. The following have complete coverage:
modules/baz.py
modules/square.py2. The following are missing coverage for the mocked function send_request(), as expected:
modules/foo.py
modules/bar.py## coverage report tip
Sometimes it's useful to see what the coverage is for a single test case, or set of test cases.
This can answer the question "Is this testcase really doing anything?"
Below we run the test case in tests/test_parametrize_1.py
```bash
rm -rf /tmp/pytest-toi
coverage run --source=./modules -m pytest tests/test_parametrize_1.py
coverage report --show-missing | grep '^Name\|square'
# output removed....
Name Stmts Miss Cover Missing
modules/square.py 5 2 60% 3
```The coverage report shows that ``raise`` in modules/square.py (line 3) is not covered, as expected.
If we rerun coverage for tests/test_parametrize_2.py, we see the ``raise`` is covered.
The text report below is actually not correct (Miss should be 0 and Cover 100%).
Looking at the html report shows that all lines ARE covered. Looks like a bug with coverage tool ``:-(``
```bash
rm -rf /tmp/pytest-toi
coverage run --source=./modules -m pytest tests/test_parametrize_2.py
coverage report --show-missing | grep '^Name\|square'
# output removed....
Name Stmts Miss Cover Missing
modules/square.py 5 1 80%
```