Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Athroniaeth committed Feb 3, 2024
1 parent dca7c8d commit 6fee861
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 17 deletions.
19 changes: 17 additions & 2 deletions docs/source/tutorials/lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
lock.lock(sum, ([1, 2, 3],))
args = [1, 2, 3]
lock.lock(sum, (args,))
```

You can choose the extension of the lock file, you just need to add argument `extension='json'` for example. The default extension is `pickle`. If you choose a extension using string like json, you must lock a function who return a json serializable object.

- `.pickle` _(default extension)_
- `.json` _(must have StrSupport with `__str__` method)_

```python
from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
args = [1, 2, 3]
lock.lock(sum, (args,), extension='.json')
```

### Locking Tests
Expand All @@ -27,7 +42,7 @@ Run pytest with the `--lock` option to generate the lock files:
pytest --lock
```

This will generate JSON files in a `.pytest-lock` directory, storing the results of the locked tests.
This will generate Pickle or JSON files in a `.pytest-lock/cache` directory, storing the results of the locked tests.

### Running Tests

Expand Down
38 changes: 38 additions & 0 deletions docs/source/tutorials/lock_clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Lock clean

## Resume
The idea is as follows: the idea is to have a command to delete all locked tests. This will delete all caches that still have an associated test using `fixture` lock. `--clean` will delete all locked tests, and you will be warned that the tests are no longer locked.

## Usage

### Create tests

Create a test file, use the __lock__ fixture, for example `test_sum.py` in the `tests` directory. Here's an example:

```python
from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
args = [1, 2, 3]
lock.lock(sum, (args,))
```

### Locking Tests
Run pytest with the `--lock` option to generate the lock files:

```bash
pytest --lock
```

This will generate Pickle files in a `.pytest-lock` directory, storing the results of the locked tests.

### Use clean

Simply run pytest with the `--clean` option to delete all locked tests:

```bash
pytest --lock --clean
```

The cache of your tests will be deleted and you will be warned that the tests are no longer locked.
3 changes: 2 additions & 1 deletion docs/source/tutorials/lock_date.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
lock.lock(sum, ([1, 2, 3],))
args = [1, 2, 3]
lock.lock(sum, (args,))
```

### Locking Tests
Expand Down
37 changes: 37 additions & 0 deletions docs/source/tutorials/lock_extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Lock tests extension

## Usage

You can choose the extension of the lock file, you just need to add `extension='json'` for example. The default extension is `pickle`. If you choose a extension using string like json, you must lock a function who return a json serializable object.

- `pickle` (default)
- `json` (must have StrSupport with `__str__` method)
### Create tests

Create a test file, use the __lock__ fixture, for example `test_sum.py` in the `tests` directory. Here's an example:

```python
from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
args = [1, 2, 3]
lock.lock(sum, (args,), extension='json')
```

### Locking Tests
Run pytest with the `--lock` option to generate the lock files:

```bash
pytest --lock
```

This will generate JSON files in a `.pytest-lock` directory, storing the results of the locked tests.

### Running Tests

Simply run pytest as you normally would:

```bash
pytest
```
11 changes: 7 additions & 4 deletions docs/source/tutorials/lock_only_skip.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
lock.lock(sum, ([],))
args = []
lock.lock(sum, (args,))
```

### Locking Tests
Expand All @@ -28,16 +29,18 @@ from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
lock.lock(sum, ([],))
args = []
lock.lock(sum, (args,))

def test_lock_sum_2(lock: FixtureLock):
lock.lock(sum, ([1, 2, 3],))
args = [1, 2, 3]
lock.lock(sum, (args,))
```

Run pytest with the `--lock` and `--only-skip` option to generate the lock files:

```bash
pytest --lock --lock-only-skip
pytest --lock --only-skip
```
The lock of `sum` with args `[]` will be skipped, but the lock of sum with args `[1, 2, 3]` will be locked.
This will generate JSON files in a `.pytest-lock` directory, storing the results of the locked tests.
Expand Down
13 changes: 3 additions & 10 deletions docs/source/tutorials/lock_simulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ from pytest_lock import FixtureLock


def test_lock_sum(lock: FixtureLock):
lock.lock(sum, ([1, 2, 3],))
args = [1, 2, 3]
lock.lock(sum, (args,))
```

### Locking Tests
Expand All @@ -28,12 +29,4 @@ Run pytest with the `--lock` and `--simulate` option to generate the lock files:
pytest --lock --simulate
```

This will not generate JSON files in a `.pytest-lock` directory and don't store the results of the locked tests.

### Running Tests

Simply run pytest as you normally would:

```bash
pytest
```
This will not generate Pickle files in a `.pytest-lock` directory and don't store the results of the locked tests.
Empty file added scripts/sphinx-build
Empty file.

0 comments on commit 6fee861

Please sign in to comment.