https://github.com/innolitics/django-utils-lib
A bundle of useful utility functions and helpers for working with Django
https://github.com/innolitics/django-utils-lib
django pytest pytest-xdist python
Last synced: 5 months ago
JSON representation
A bundle of useful utility functions and helpers for working with Django
- Host: GitHub
- URL: https://github.com/innolitics/django-utils-lib
- Owner: innolitics
- Created: 2024-09-14T03:43:46.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-08-06T23:00:56.000Z (11 months ago)
- Last Synced: 2026-01-13T07:45:08.498Z (5 months ago)
- Topics: django, pytest, pytest-xdist, python
- Language: Python
- Homepage:
- Size: 162 KB
- Stars: 2
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Django Utils Lib
> A bundle of useful utility functions and helpers for working with Django
## Core Features
- Pytest plugin, with commonly needed items
- Support for automated debugpy listener
- Support for `requirements()` markers
- Support for test collection, with CSV export (including with xdist)
- An extensible static file serving class / middleware, which has a few bells and whistles in comparison to the default `serve()` method
- Logging utils (presets, formatters, etc.)
- CLI / pre-built commands (see [](./django_utils_lib/commands.py))
- CLI Utils
## Installing and Using (as a library)
While this project is not published on `pypi`, you can still install it in various projects by using the git origin as the source.
For example, [with Poetry](https://python-poetry.org/docs/dependency-specification/#git-dependencies), you can use:
```bash
poetry add git+https://github.com/innolitics/django-utils-lib.git#REFERENCE
```
## Pytest plugin
### Pytest Plugin - Discovery / Registration
This package is not using pytests [automated entry points](https://docs.pytest.org/en/stable/how-to/writing_plugins.html#pip-installable-plugins), instead requiring that users manually opt-in to plugin usage (since you might want other utilities in this package without enabling the pytest plugin part of it).
To tell Pytest to use the plugin, the easiest way is to stick this in your highest level `.conftest.py` (aka the _root_ config):
```py
pytest_plugins = ["django_utils_lib.testing.pytest_plugin"]
```
### Pytest Plugin - Configuration
> [!TIP]
> Note: This table was auto-generated from the source-code (and can be re-generated) via `task docs:pytest_plugin_table`
| Config Key | Type | Default | Help | Env Var? |
|------------|------|---------|------|---------------|
| `auto_debug` | `bool` | `False` | If true, the debugpy listener will be auto-invoked on the main pytest session.
You can also enable this by setting `django_utils_lib_AUTO_DEBUG` as an environment variable. | `django_utils_lib_AUTO_DEBUG`: If set to any truthy value (`bool()`), will enable auto-debugging. Unless `CI` is set to `true`. |
| `auto_debug_wait_for_connect` | `bool` | `False` | If true, then the auto debug feature will wait for the debugger client to connect before starting tests | `django_utils_lib_AUTO_DEBUG_WAIT_FOR_CONNECT`: If set to any truthy value (`bool()`), will enable waiting for debugger client to connect. |
| `mandate_requirement_markers` | `bool` | `False` | If true, will validate that every test has a valid `pytest.mark.requirements`, and will also capture this metadata as part of the collected test data | N/A |
| `reporting__csv_export_path` | `string` | `None` | If set, will save the test results to a CSV file after session completion | `django_utils_lib_REPORTING__CSV_EXPORT_PATH`: If set, will save the test results to a CSV file after session completion |
| `reporting__omit_unexecuted_tests` | `bool` | `False` | If set, will exclude tests that were collected but not executed from the test report CSV | N/A |
## Development
This project uses [`task` (aka `go-task`)](https://github.com/go-task/task) for developer task management and execution. [The `Taskfile.yml` file](./Taskfile.yml) serves as a way to organize these commands, as well as a form of documentation and easy entrypoint into getting started with the project.
You can use `task --list-all` to see all available `task` commands.
### Local Installation Cross-Directory
If you want to install a local development version of this library, in a different directory / project, you should be able to use the local path of the library in most standard Python package managers.
For example, this can be accomplished with Poetry with the following:
```bash
poetry add --editable ${LOCAL_PATH_TO_THIS_DIRECTORY}
```
### Publishing
TBD; right now this is not published on `pypi`, but is available publicly.