Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move pytest plugin #1522

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Version next
--------------

- Fix file permissions in Windows.
- Move location of pytest plugin.

Version 15.1.0
--------------
Expand Down
35 changes: 0 additions & 35 deletions mimesis/plugins/pytest.py

This file was deleted.

Empty file.
41 changes: 41 additions & 0 deletions mimesis_pytest_plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import TYPE_CHECKING, Callable, TypeAlias # pragma: no cover

if TYPE_CHECKING:
from mimesis.locales import Locale
from mimesis.schema import Field

try: # pragma: no cover
import pytest
except ImportError: # pragma: no cover
raise ImportError("pytest is required to use this plugin")


_CacheCallable: TypeAlias = "Callable[[Locale], Field]" # pragma: no cover


@pytest.fixture(scope="session")
def _mimesis_cache() -> _CacheCallable:

Check warning on line 17 in mimesis_pytest_plugin/plugin.py

View check run for this annotation

Codecov / codecov/patch

mimesis_pytest_plugin/plugin.py#L16-L17

Added lines #L16 - L17 were not covered by tests
from mimesis.schema import Field

cached_instances: "dict[Locale, Field]" = {}

def factory(locale: "Locale") -> "Field":
if locale not in cached_instances:
cached_instances[locale] = Field(locale)
return cached_instances[locale]

return factory


@pytest.fixture()
def mimesis_locale() -> "Locale":

Check warning on line 31 in mimesis_pytest_plugin/plugin.py

View check run for this annotation

Codecov / codecov/patch

mimesis_pytest_plugin/plugin.py#L30-L31

Added lines #L30 - L31 were not covered by tests
"""Specifies which locale to use."""
from mimesis.locales import Locale

return Locale.DEFAULT


@pytest.fixture()
def mimesis(_mimesis_cache: _CacheCallable, mimesis_locale: "Locale") -> "Field":

Check warning on line 39 in mimesis_pytest_plugin/plugin.py

View check run for this annotation

Codecov / codecov/patch

mimesis_pytest_plugin/plugin.py#L38-L39

Added lines #L38 - L39 were not covered by tests
"""Mimesis fixture to provide fake data using all built-in providers."""
return _mimesis_cache(mimesis_locale)
21 changes: 9 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ keywords = [
"polars",
"pytest",
"factory",
"factory_boy"
"factory_boy",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand All @@ -46,9 +46,8 @@ classifiers = [
"Topic :: Software Development :: Testing",
"License :: OSI Approved :: MIT License",
]
exclude = [
"mimesis/datasets/locale_template",
]
exclude = ["mimesis/datasets/locale_template"]
packages = [{ include = "mimesis" }, { include = "mimesis_pytest_plugin" }]

[tool.poetry.dependencies]
python = "^3.10"
Expand Down Expand Up @@ -86,18 +85,14 @@ factory = ["factory-boy"]
mimesis = "mimesis.entrypoints:pytest_randomly_reseed"

[tool.poetry.plugins.pytest11]
mimesis = "mimesis.plugins.pytest"
mimesis = "mimesis_pytest_plugin.plugin"

[tool.pytest.ini_options]
testpaths = [
"mimesis",
"tests",
"minifier.py",
]
testpaths = ["mimesis", "tests", "minifier.py"]

[tool.mypy]
exclude = ["tests", "docs"]
files = ["mimesis", "minifier.py"]
files = ["mimesis", "minifier.py", "mimesis_pytest_plugin/plugin.py"]
strict_optional = true
check_untyped_defs = true
ignore_errors = false
Expand All @@ -116,6 +111,9 @@ no_implicit_optional = true
warn_return_any = true
strict_equality = true

[tool.coverage.report]
exclude_also = ["if TYPE_CHECKING:"]

[tool.isort]
profile = "wemake"

Expand All @@ -124,4 +122,3 @@ minify = "python minifier.py"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

poetry run mypy mimesis
poetry run pytest --cov=mimesis --cov-report=xml --randomly-seed=$RANDOM
poetry run pytest --cov=mimesis --cov=mimesis_pytest_plugin --cov-report=xml --randomly-seed=$RANDOM
Loading