Code Monkey home page Code Monkey logo

pytest-canon's Introduction

Example

???????? Python ???? Testing ????? Canonization ??????

???? It is good, use it and enjoy ????

Actions Status Codecov Language grade: Python License: MIT PyPI PyPI Annotations coverage No-OOP coverage Dependencies Gitter


“Doesn't pytest have it out of the box?” – Boris Kovarsky

Surprisingly enough, it does not.


Contents: Installation | Quick Start | How does it save my time? | Examples and recipes | Reference


Installation

pip install pytest-canon

Quick Start

Simplest usage, a single line:

    def test_case_1:
        ...
        assert_equals_ref(very_long_multiline_string, 'test_case_1')

Run tests (e.g. with pytest):

    pytest  # that's it :)

Update tests (e.g. with pytest):

    PYTEST_UPDATE_REFS=1 pytest

Set different dump location:

    set_global_dir_path('other_dir')

Set different string comparison:

    set_global_cast_func(lambda s: s.lower())

Customize a single test:

    def test_case_1():
        assert_equal_ref(long_string, 'test_case_1', cast_func=lambda s: s.lower())

How does it save my time?

  • Reason 1

    ??????

  • Reason 2

    ?????

  • Reason 3

    ??????

Examples and recipes

Reference

Either compares a string value with a dumped one or dumps it depending on env_var value.

Optional arguments:
dir_path: str or Path, dir with dumps, default='tests/dumps'
env_var: str ,env variable activating tests updates, default='PYTEST_UPDATE_REFS'
assert_func: assert function (str, str) -> NoReturn
cast_func: casting function str -> str


Global setters for every optional argument of assert_equals_ref

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.