diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef427e3d..ee7af3fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/docs/fixtures/builtin.md b/docs/fixtures/builtin.md new file mode 100644 index 00000000..32fc0436 --- /dev/null +++ b/docs/fixtures/builtin.md @@ -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' +``` diff --git a/docs/fixtures.md b/docs/fixtures/fixtures.md similarity index 81% rename from docs/fixtures.md rename to docs/fixtures/fixtures.md index 7ebea067..96cb217d 100644 --- a/docs/fixtures.md +++ b/docs/fixtures/fixtures.md @@ -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: @@ -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' -``` diff --git a/zensical.toml b/zensical.toml index 23bfe323..7a7c0b26 100644 --- a/zensical.toml +++ b/zensical.toml @@ -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"},