Metadata-Version: 2.3
Name: import-volkswagen
Version: 0.1.1
Summary: Detect if running in a testing environment and control if methods act (either no-op in a test, or only act in a test)
License: MIT
Author: Matthew
Author-email: 2565361+mshafer1@users.noreply.github.com
Requires-Python: >=3.8.1,<4.0.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Manufacturing
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Dist: python-decouple (>=3.8,<4.0)
Project-URL: Documentation, https://mshafer1.github.io/py-vw/
Project-URL: Repository, https://github.com/mshafer1/py-vw
Description-Content-Type: text/markdown

# VW

This module provides decorators that turn on or off the decorated method depending on 
whether it is running in a testing environment or not.

**NOTE**: The name `vw` was chosen for convenience and is not intended as commentary on any political topic real or imagined.

# Why?

Have you ever found yourself wanting an easy way to turn off the logging when running in tests?

What about database access?

[Mocking](https://docs.python.org/3/library/unittest.mock.html) works well for your own code, but what about when a user imports your library?

This is what this tool is meant to solve.

# Controlling

By using [python-decouple](https://pypi.org/project/python-decouple/), the following variables can be set in a `settings.ini` file, or a `.env` file, or as variables in the environment.

- `VW_IGNORE` -> causes VW to ignore if it is in a test environment (`no_op` still acts, and `tests_only` will not)
- `VW_ALWAYS` -> (NOTE: `VW_IGNORE` takes precedence over this var) causes VW to behave like it is always in a test environment (`no_op` is always a no-op)

# Examples

1. Using an in-memory db for tests:

    ```python
    import sqlite3

    import vw

    _con = sqlite3.connect(":memory:" if vw.is_test_env() else "database.sqlite3")
    ```

1. Logging to a local file for tests

    ```python
    import logging

    import vw

    _root_logger = logging.getLogger(None)
    _root_logger.addHandler(logging.FileHandler("test.log" if vw.is_test_env() else "//path/to/server/log.txt"))
    ```

1. Avoid doing things in unit/component/integration tests that should only be done in production

    ```python
    import requests
    import vw

    @vw.no_op
    def send_tornado_warning():
        requests.post(...)
    ```

