Giter VIP home page Giter VIP logo

pytest-mimesis's Introduction

⛔️ DEPRECATED

This repository is now deprecated. We have integrated pytest-mimesis into mimesis itself, and there is no longer a need to use a separate package. Refer to the Integration with Pytest section for more details.

pytest-mimesis

test wemake-python-styleguide Python Version

pytest-mimesis is a pytest plugin that provides pytest fixtures for Mimesis providers. This allows you to quickly and easily use randomized, dummy data as part of your test suite.

Installation

pip install pytest-mimesis

Examples

Using the personal provider as part of a test.

# your_module/__init__.py

def validate_email(email):
    # code that validates an e-mail address
    return True

And your test file:

# tests/test_email.py

from your_module import validate_email

def test_validate_email(mimesis):
    assert validate_email(mimesis('email'))

You can also specify locales:

@pytest.mark.parameterize('mimesis_locale', ['de'])  # use German locale
def test_create_user(mimesis):
    assert create_user(name=mimesis('full_name'))


@pytest.mark.parameterize('mimesis_locale', ['de', 'en', 'jp'])  # test multiple locales
def test_add_phone(user, mimesis):
    assert user.add_phone_number(name=mimesis('full_name'))

Fixtures

We provide two public fixtures: mimesis_locale and mimesis. While mimesis_locale is just a string (like: en, ru), mimesis is an instance of mimesis.schema.Field.

We use caching of mimesis instances for different locales for the whole test session, so creating new instances is cheap.

Related projects

You might also be interested in:

License

pytest-mimesis is licensed under the MIT License.

pytest-mimesis's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar eumiro avatar geyser avatar hugovk avatar lk-geimfari avatar sobolevn avatar wikkiewikkie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytest-mimesis's Issues

Allow adding custom providers

I suggest to support a fixture something like mimesis_custom_providers, that should return a list of providers to register.

We need to properly scope this fixture, so it would be:

  1. fast enough (not function scope), since adding providers might be kind of expensive
  2. configurable, so different module could have different providers

Version missmatch

Using version ^1.0 for pytest-mimesis

Updating dependencies
Resolving dependencies... (0.8s)
                                                                                      
[SolverProblemError]                                                   
Because no versions of pytest-mimesis match >1.0,<2.0                               
 and pytest-mimesis (1.0.0) depends on pytest (>=4.2), pytest-mimesis (>=1.0,<2.0)  
 requires pytest (>=4.2).                                                           
So, because rostelecom-svetochka depends on both pytest (^3.10.0) and pytest-mimes  
is (^1.0), version solving failed.                                                  
                                                                                      
add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...

Support fixture parametrization

Imagine I have the following fixture:

@pytest.fixture(scope='function')
def gitlab_merge_request(mimesis):
    return {
        'user': {
            'username': mimesis('username'),
        },
        'object_attributes': {
            'id': mimesis('between', minimum=1),
            'state': 'opened'
        },
    }

What I want to achieve is something like:

import pytest

@pytest.mark.parametrize(
    'gitlab_merge_request__object_attributes__state', ['closed'],
)
def test_is_closed(gitlab_merge_request):
    assert gitlab_merge_request['object_attributes']['state'] == 'closed'

We can use https://docs.pytest.org/en/latest/fixture.html#override-a-fixture-with-direct-test-parametrization

consider moving code into mimesis.pytest_plugin

then this project can be a thin shim that just registers the entry point:

[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "pytest_mimesis"
dist-name = "pytest-mimesis"
author = "..."
author-email = "..."
home-page = "https://github.com/lk-geimfari/mimesis/tree/master/mimesis/pytest_plugin.py"
license = "..."
classifiers = ["..."]
requires = ["mimesis >= 4.2.0"]

[tool.flit.entrypoints.pytest11]
mimesis = "mimesis.pytest_plugin"

this is the approach used by pytest-celery:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.