Giter Site home page Giter Site logo

rafaelhenrique / pytest-envvars Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 5.0 113 KB

Pytest plugin to validate use of envvars on your tests

License: MIT License

Python 94.93% Makefile 3.62% HTML 1.45%
pytest testing environment-variables envvars environments

pytest-envvars's Introduction

pytest-envvars

See Build Status on Travis CI

Pytest plugin to validate use of envvars on your tests

What is pytest-envvars?

pytest-envvars randomize values of environment variables on your unit tests to check consistency of mocks about configuration. If the test has a wrong mock, this test will be broken.

Install

$ pip install pytest-envvars

Use

You need write some changes on pytest.ini file, like that...

[pytest]
pytestenvvars__env_files =
    .env
pytestenvvars__dont_randomize_envvars =
    CACHE_URL

On this example above the plugin read .env file (from pytestenvvars__env_files section) of your project and randomize ALL envvar configuration on that file, if you dont need randomize some envvar configuration you need add this envvar to pytestenvvars__dont_randomize_envvars section like shown above.

Before that configuration to run validation you need run pytest with flag --validate-envvars, like that...

pytest --validate-envvars

To debug purpose you can use --envvars-value to set a default value for all envvars. This parameter accept only two options 0 or 1, see this example:

pytest --validate-envvars --envvars-value=0

Using the plugin that way you will apply the value 0 to ALL of your envvars.

pytest-envvars's People

Contributors

hartungstenio avatar jfunez avatar rafaelhenrique avatar

Stargazers

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

Watchers

 avatar  avatar

pytest-envvars's Issues

Create more efficient tests to parse envvars

This part is not tested correctly...

envvar, _, value = line.partition('=')
envvar = envvar.strip()
value = value.strip()

We need more tests with cases:

  • ENVVAR===somehash==
  • ENVVAR=@
  • ENVVAR=rafael

Improve output from plugin

Now we have a problem, when some test fail, we dont have an beatiful and informative output about what is the cause of the fail.

We need a beautiful output like these:

These test <test_name> fails because do you have an incorrect mock of your envvars, check this!

Sample app

Create a sample app using either django and flask to explain use of pytest-envvars.

Implement "ignore envvar" feature for Flask framework

Now this project support some "default ignored" envvars for Django Framework. There is a possibility to implement this same feature in the Flask framework.

We need an new file called "flask_utills.py" (like django_utils.py) , and implement a new functions like these:

  • is_django_project: This function check if this is an django project;
  • get_base_envvars: This function get a base envvars used in django (ignoring a custom envvars).

For flask i suggest these names:

  • is_flask_project: This function check if this is an flask project;
  • get_base_envvars: This function get a base envvars used in flask (ignoring a custom envvars).

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.