Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ exclude =
dist,
.flask8,
venv

max-complexity = 10

max-line-length = 100

filename = *.py
57 changes: 51 additions & 6 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,69 @@ name: Python multi version tests
on:
push:
branches: [ 'main' ]
pull_request:
branches: [ 'main' ]
schedule:
# Run every 05:00 AM on the 1st day of every month
- cron: '0 5 1 * *'
# Run every 05:00 AM
- cron: '0 5 * * *'
jobs:
pytest-version-check:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.decision.outputs.should_run }}
steps:
- uses: actions/checkout@v4
- name: Restore last version
id: cache-pytest
uses: actions/cache@v4
with:
path: last_pytest_version.txt
key: pytest-version-cache-${{ github.run_id }}
restore-keys: pytest-version-cache-
- name: Fetch Latest Pytest
id: pypi
run: |
LATEST=$(curl -s https://pypi.org/pypi/pytest/json | jq -r '.info.version')
echo "latest=$LATEST" >> $GITHUB_OUTPUT
[ -f last_pytest_version.txt ] && LAST=$(cat last_pytest_version.txt) || LAST="0.0.0"
echo "last=$LAST" >> $GITHUB_OUTPUT
- name: Determine if we should run
id: decision
run: |
if [[ "${{ github.event_name }}" != "schedule" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
elif [[ "${{ steps.pypi.outputs.latest }}" != "${{ steps.pypi.outputs.last }}" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
else
echo "should_run=false" >> $GITHUB_OUTPUT
fi
- name: Cancel if no update
if: steps.decision.outputs.should_run == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "No new pytest version. Cancelling and deleting run."
gh run delete ${{ github.run_id }}
test:
needs: pytest-version-check
if: needs.pytest-version-check.outputs.should_run == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: true
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
pytest-version: ['7.0.1', 'latest']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install testing dependencies
run: |
python -m pip install --upgrade pip
python -m pip install coverage deepdiff parameterized
- name: Install application dependencies
- name: Install application dependencies
run: |
grep -v pytest requirements.txt > requirements_without_pytest.txt || true

Expand All @@ -42,6 +83,10 @@ jobs:
- name: Test with pytest
run: |
python tests_execution.py
- name: Update last pytest version
if: github.event_name == 'schedule' && success()
run: |
echo "${{ needs.pytest-version-check.outputs.latest }}" > last_pytest_version.txt
- name: Send lcov.info to coveralls
uses: coverallsapp/github-action@master
with:
Expand Down
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ To verify the soft asserts in the middle of the test, call `sa.assert_all()`.<br
<br/>
assert_all() will raise _AssertionError_ if any of the asserts failed.<br/>

### With statement
### ith statement

Soft asserts can be used in 'with' statement.<br/>
Soft asserts can be used in `with` statement.<br/>
<br/>
#### Example 1

Expand Down Expand Up @@ -76,11 +76,30 @@ with SoftAsserts() as sa:
sa.assert_equal(1, 2, 'Second assert failed')
```

### aync context manager
Soft asserts can be used in `async with` statement.<br/>
<br/>
#### Example
```python
import asyncio
from nrt_pytest_soft_asserts.soft_asserts import SoftAsserts

async def print_on_failure():
print('Assertion failed!')
async def test_assert_with_async_statement():
async with SoftAsserts() as sa:
sa.assert_true(False, 'First assert failed')
sa.assert_equal(1, 2, 'Second assert failed')

asyncio.run(test_assert_with_async_statement())
```

### soft_asserts decorator
Soft asserts can be used as a decorator.<br/>
Soft asserts decorator supports also async test functions.<br/>
The assert_all() method will be run in the decorator, so it is not needed to run in the test itself.<br/>

#### Example
#### Example 1

```python
import pytest
Expand All @@ -95,6 +114,21 @@ def test_assert_with_decorator():
sa.assert_equal(1, 2, 'Second assert failed')
```

#### Example 2

```python
import pytest
from nrt_pytest_soft_asserts.soft_asserts import SoftAsserts, soft_asserts


sa = SoftAsserts()

@soft_asserts(sa=sa)
async def test_assert_with_decorator_async():
sa.assert_true(False, 'First assert failed')
sa.assert_equal(1, 2, 'Second assert failed')
```

### Steps

Each testing section can be divided to steps.<br/>
Expand Down
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Version History

### Version 2.0.0

- Support for asynchronous context managers. `async with SoftAsserts()` and `async with sa.assert_raised_with`.

### Version 1.4.1

- Add new assertion method: `assert_greater`, `assert_greater_equal`, `assert_less`, `assert_less_equal`.
Expand Down
Loading
Loading