Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #53 from darrenburns/using-decorator
Browse files Browse the repository at this point in the history
Using decorator
  • Loading branch information
darrenburns authored Nov 8, 2019
2 parents c1fcdfe + 5550e84 commit 745ae34
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name matching.
* **Powerful test selection:** limit your test run not only by matching test names/descriptions, but also on the code
contained in the body of the test.
* **Colourful, human readable output:** quickly pinpoint and fix issues with detailed output for failing tests.
* **Parameterised testing:** easily parameterise your tests using `each`.
* **Expect API:** A simple but powerful assertion API inspired by [Jest](https://jestjs.io).
* **Cross platform:** Tested on Mac OS, Linux, and Windows.
* **Zero config:** Sensible defaults mean running `ward` with no arguments is enough to get started.
Expand Down Expand Up @@ -48,11 +49,13 @@ def _():
Now run your test with `ward` (no arguments needed). Ward will output the following:

```
PASS test_sum: 1 plus 2 equals 3
PASS test_sum:2: 1 plus 2 equals 3
```

*You've just wrote your first test with Ward, congrats!*

[See the official documentation for more examples.](https://wardpy.com)

## How to Contribute

Contributions are very welcome and encouraged!
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

version = "0.15.0a0"
version = "0.16.0a0"
description = "A modern Python 3 test framework for finding and fixing flaws faster."
with open("README.md", "r") as fh:
if platform.system() != "Windows":
Expand Down
2 changes: 1 addition & 1 deletion ward/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .expect import expect, raises
from .fixtures import fixture
from .fixtures import fixture, using
from .testing import each, skip, test, xfail
from .models import Scope
19 changes: 19 additions & 0 deletions ward/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,22 @@ def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper


def using(*using_args, **using_kwargs):
def decorator_using(func):

signature = inspect.signature(func)
bound_args = signature.bind_partial(*using_args, **using_kwargs)
if hasattr(func, "ward_meta"):
func.ward_meta.bound_args = bound_args
else:
func.ward_meta = WardMeta(bound_args=bound_args)

@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper

return decorator_using
2 changes: 2 additions & 0 deletions ward/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from enum import Enum
from inspect import Signature
from typing import Optional

from ward.errors import FixtureError
Expand Down Expand Up @@ -41,3 +42,4 @@ class WardMeta:
description: Optional[str] = None
is_fixture: bool = False
scope: Scope = Scope.Test
bound_args: Optional[Signature] = None

0 comments on commit 745ae34

Please sign in to comment.