https://github.com/chairchandler/django-fixtures
Package for testing django to facilitate access to fixtures.
https://github.com/chairchandler/django-fixtures
django django-fixtures django-testing injection pytest testing-tools
Last synced: 2 months ago
JSON representation
Package for testing django to facilitate access to fixtures.
- Host: GitHub
- URL: https://github.com/chairchandler/django-fixtures
- Owner: ChairChandler
- License: mit
- Created: 2024-10-20T20:30:41.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-10-21T16:19:21.000Z (7 months ago)
- Last Synced: 2025-01-17T08:12:42.626Z (4 months ago)
- Topics: django, django-fixtures, django-testing, injection, pytest, testing-tools
- Language: Python
- Homepage:
- Size: 197 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Description
## Overview
Injects fixture into methods arguments from class properties a.k.a namespace.
Namespace is a class designed to be build on top of properties, `@property` and `@cached_property` annotated methods.
To inject fixtures in a test class, methods in a test class must starts with a `test` name. Fixtures are loaded in namespace class definition order.
`@unzip` decorator allows to load generator/mock directly without calling `next(mock)` on it. All generators (marked with **unzip** or without) are automatically closed after test is done.
Tests can be copy using `@func_copy` decorator with renaming arguments using **map_args**. Copy cannot be done in the same namespace.
Example:
```python
class FixtureNamespace:
@property
def words(self):
return ['a', 'b', 'c']@cached_property
def something(self):
return self.words + ['d']
@property # or @cached_property
@fixture.unzip
def mock(self):
with patch('path.to.Mock') as mock:
yield mock@fixture.use_fixture_namespace(FixtureNamespace)
class TestClass:
def test_words(self, words):
assert words == ['a', 'b', 'c']def test_something(self, something, mock):
assert something == ['a', 'b', 'c', 'd']
assert isinstance(mock, Mock)class AnotherNamespace:
@property
def words(self):
return ['X', 'Y']@property
def something(self):
return 'xyz'@property
def new_mock_name(self):
return 123@fixture.use_fixture_namespace(AnotherNamespace)
class AnotherClass:
@fixture.func_copy(TestClass.test_words)
def test_copy_1(): ...@fixture.func_copy(
TestClass.test_something,
map_args={'mock': 'new_mock_name'}
)
def test_copy_2(): ...
```## Source code
**src** directory contains a single file **base.py**, with a decorator `use_fixture_namespace` designed for injecting properties into test classes from a specified namespace.
## Testing
**tests** directory contains a single file **base_test.py**, with a unit tests for a `use_fixture_namespace` decorator.
To run tests, run script **run_tests.sh** inside **scripts** directory. It will generates unit tests report and coverage report inside **reports** directory.
## Building
To build a package run **run_build.sh** inside **scripts** directory. It will generate **whl** package file inside **dist** directory.
## Installation
Being inside package base directory run
> pip install dist/.whl