Metadata-Version: 2.4
Name: pytest-tzshift
Version: 0.1.1
Summary: A Pytest plugin that transparently re-runs tests under a matrix of timezones and locales.
Author-email: Pedro Sanvido <pedro.sanvido@acad.pucrs.br>
Maintainer-email: Pedro Sanvido <pedro.sanvido@acad.pucrs.br>
License: 
        The MIT License (MIT)
        
        Copyright (c) 2025 Pedro Sanvido
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
        
Project-URL: Repository, https://github.com/spedr/pytest-tzshift
Classifier: Framework :: Pytest
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Testing
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
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 :: Only
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pytest>=7.0
Requires-Dist: backports.zoneinfo>=0.2.1; python_version < "3.9"
Requires-Dist: tzdata>=2024.1
Dynamic: license-file

# pytest-tzshift

[![PyPI version](https://img.shields.io/pypi/v/pytest-tzshift.svg)](https://pypi.org/project/pytest-tzshift/)
[![CI](https://github.com/spedr/pytest-tzshift/actions/workflows/ci.yml/badge.svg)](https://github.com/spedr/pytest-tzshift/actions/workflows/ci.yml)
![License](https://img.shields.io/badge/license-MIT-blue.svg)

*A tiny Pytest plug-in that automatically re-runs your tests under a matrix of time-zones and locales.*


## Why?

Time-zones and locales are global process settings.
If your code formats dates, parses user input, or depends on `datetime.now()`, it may behave differently on users' machines.

`pytest-tzshift` attempts to make these differences visible:

```text
tests/test_format.py::test_human_readable[0|UTC|C]                  PASSED
tests/test_format.py::test_human_readable[1|America/New_York|C]     PASSED
tests/test_format.py::test_human_readable[2|Europe/Berlin|de_DE]    FAILED
```


## Installation

```bash
pip install pytest-tzshift          # requires Python ≥ 3.9
```

No further setup is necessary. The plug-in is auto-discovered by Pytest.


## Quick start

Add the `tzshift` fixture to any test:

```python
def test_price_formatting(tzshift):
    tz, loc = tzshift              # tuple-unpack

    price = 1234.56
    formatted = format_price(price)    # your code

    assert formatted.endswith("€") if loc.startswith("de_") else "€" not in formatted
```

Run Pytest as usual; each test will execute for every `(timezone, locale)` pair.


## Default matrix

| Time-zones (IANA)  | Locales (POSIX / glibc) |
| ------------------ | ----------------------- |
| `UTC`              | `C`                     |
| `America/New_York` | `en_US.UTF-8`           |
| `Europe/London`    | `de_DE.UTF-8`           |
| `Asia/Kolkata`     | `fr_FR.UTF-8`           |
| `Australia/Sydney` | `ja_JP.UTF-8`           |
| `Asia/Tokyo`       |                         |

Unavailable zones/locales are skipped with a warning.


## Customising the matrix

### Project-wide (`pytest.ini`)

```ini
[pytest]
tz_timezones =
    SYSTEM          # keep OS default
    Europe/Paris
tz_locales =
    SYSTEM
    fr_FR.UTF-8
tzshift_max = 10     # cap the total Cartesian product (0 = unlimited)
```

### Command line

```bash
pytest --tz-timezones=UTC,Asia/Tokyo --tz-locales=C,ja_JP.UTF-8
pytest --tzshift-max=20
pytest --no-tzshift                     # disable for this run
```

### Per-test marker

```python
import pytest

@pytest.mark.tzshift(timezones=["UTC"], locales=["C"])
def test_once_only(tzshift):
    ...

@pytest.mark.tzshift(disable=True)
def test_native_env():
    ...
```


## Platform notes

* On **Windows**, `time.tzset()` is missing; the time-zone part becomes a no-op (locales still work).
  You'll still see separate parametrised runs, but all in the system zone.
* Changing the process locale is global; avoid running `pytest-tzshift` with parallel workers.


## Documentation

* **Quick start** – `docs/usage/quickstart.md`
* **Configuration details** – `docs/usage/configuration.md`
* **Markers & fixtures** – `docs/usage/markers.md`
* **API reference** – `docs/reference/api.md`

Browse the full site at **[https://spedr.github.io/pytest-tzshift](https://spedr.github.io/pytest-tzshift)** once published.


## Contributing

Bug reports, feature ideas, and pull requests are warmly welcome!
See [CONTRIBUTING](docs/contributing.md) for tips on setting up a dev environment, coding style, and running the test suite.


## License

Released under the [MIT License](LICENSE).
