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
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ jobs:
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
run: |
if git diff --quiet "${MERGE_BASE}...HEAD" -- \
':!docs/**' \
. \
':!docs/' \
':!CODE_OF_CONDUCT.md' \
':!CONTRIBUTING.md' \
':!LICENSE' \
':!pyproject.toml' \
':!README.md' \
':!zensical.toml' \
; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

pre-commit:
Expand Down
41 changes: 41 additions & 0 deletions docs/fixtures/builtin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Karva provides a few built-in fixtures that can be used in your tests.

We will try to add more built-in fixtures from pytest in the future.

## Temporary Directory

This fixture provides the user with a `pathlib.Path` object that points to a temporary directory.

You can use any of the following fixture names:

- `tmp_path` (from pytest)
- `tmpdir` (from pytest)
- `temp_path` (from karva)
- `temp_dir` (from karva)

```py title="test.py"
def test_tmp_path(tmp_path):
assert tmp_path.is_dir()
```

## Mock Environment

This fixture allows you to safely modify environment variables, and the system path during tests. All changes are automatically undone after the test completes.

You can use any of the following fixture names:

- `monkeypatch` (from pytest)

This fixture is compatible with pytest's `monkeypatch` fixture.

```py title="test.py"
def test_setattr(monkeypatch):
import os
monkeypatch.setattr(os, 'getcwd', lambda: '/fake/path')
assert os.getcwd() == '/fake/path'

def test_setenv(monkeypatch):
monkeypatch.setenv('MY_VAR', 'test_value')
import os
assert os.environ['MY_VAR'] == 'test_value'
```
41 changes: 1 addition & 40 deletions docs/fixtures.md → docs/fixtures/fixtures.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
## Constraints

We only discover package level fixtures from a `conftest.py` file in the root of that package.

## Fixture Types
## Fixture Scopes

Karva supports different types of fixtures based on their scope:

Expand Down Expand Up @@ -225,38 +221,3 @@ In future you will be able to access other parameters.

It is important to note that this request object is not the same as the pytest `FixtureRequest` object. It is a custom object provided by Karva.
And so it may not have all of the information that the pytest `FixtureRequest` object has.

## Built-in fixtures

Karva provides a few built-in fixtures that can be used in your tests.

We will try to add more built-in fixtures from pytest in the future.

### Temporary Directory

This fixture provides the user with a `pathlib.Path` object that points to a temporary directory.

You can use any of the following fixture names to use this fixture:

- `tmp_path` (from pytest)
- `tmpdir` (from pytest)
- `temp_path` (from karva)
- `temp_dir` (from karva)

### Monkeypatch

The `monkeypatch` fixture allows you to safely modify objects, dictionaries, environment variables, and the system path during tests. All changes are automatically undone after the test completes.

This fixture is compatible with pytest's `monkeypatch` fixture.

```py
def test_setattr(monkeypatch):
import os
monkeypatch.setattr(os, 'getcwd', lambda: '/fake/path')
assert os.getcwd() == '/fake/path'

def test_setenv(monkeypatch):
monkeypatch.setenv('MY_VAR', 'test_value')
import os
assert os.environ['MY_VAR'] == 'test_value'
```
5 changes: 4 additions & 1 deletion zensical.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ nav = [
{ "Home" = "index.md"},
{ "Installation" = "installation.md"},
{ "Tutorial" = "tutorial.md"},
{ "Fixtures" = "fixtures.md"},
{ "Fixtures" = [
{ "Fixtures" = "fixtures/fixtures.md"},
{ "Built In" = "fixtures/builtin.md"},
]},
{ "Tags" = [
{ "Parametrize" = "tags/parametrize.md"},
{ "Skip" = "tags/skip.md"},
Expand Down
Loading