All Projects → typeddjango → Pytest Mypy Plugins

typeddjango / Pytest Mypy Plugins

Licence: mit
pytest plugin for testing mypy types, stubs, and plugins

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Pytest Mypy Plugins

Allure Python
Allure integrations for Python test frameworks
Stars: ✭ 387 (+723.4%)
Mutual labels:  pytest
Pytest Responsemock
Simplified requests calls mocking for pytest
Stars: ✭ 24 (-48.94%)
Mutual labels:  pytest
Opensourcetest
OpenSourceTest由自动化测试-夜行者社区维护,提供的是更多地灵活性和可配置性
Stars: ✭ 37 (-21.28%)
Mutual labels:  pytest
Coveralls Python
Show coverage stats online via coveralls.io
Stars: ✭ 455 (+868.09%)
Mutual labels:  pytest
Schemathesis
A modern API testing tool for web applications built with Open API and GraphQL specifications.
Stars: ✭ 768 (+1534.04%)
Mutual labels:  pytest
Pytest Patterns
A couple of examples showing how pytest and its plugins can be combined to solve real-world needs.
Stars: ✭ 24 (-48.94%)
Mutual labels:  pytest
Python Best Practices Cookiecutter
Python best practices project cookiecutter 🍪
Stars: ✭ 286 (+508.51%)
Mutual labels:  pytest
Pytest Pudb
Pytest PuDB debugger integration
Stars: ✭ 45 (-4.26%)
Mutual labels:  pytest
Pytest Ui
Text User Interface for running python tests
Stars: ✭ 23 (-51.06%)
Mutual labels:  pytest
Pytest Cov
Coverage plugin for pytest.
Stars: ✭ 983 (+1991.49%)
Mutual labels:  pytest
Pytest Sugar
a plugin for py.test that changes the default look and feel of py.test (e.g. progressbar, show tests that fail instantly)
Stars: ✭ 689 (+1365.96%)
Mutual labels:  pytest
Tavern
A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax
Stars: ✭ 760 (+1517.02%)
Mutual labels:  pytest
Pytest Django
A Django plugin for pytest.
Stars: ✭ 872 (+1755.32%)
Mutual labels:  pytest
Pytest Html
Plugin for generating HTML reports for pytest results
Stars: ✭ 404 (+759.57%)
Mutual labels:  pytest
Pytest Mock
Thin-wrapper around the mock package for easier use with pytest
Stars: ✭ 1,020 (+2070.21%)
Mutual labels:  pytest
Nbval
A py.test plugin to validate Jupyter notebooks
Stars: ✭ 347 (+638.3%)
Mutual labels:  pytest
Pytest Requests
HTTP(S) testing with pytest and requests.
Stars: ✭ 24 (-48.94%)
Mutual labels:  pytest
Pytest Mimesis
Mimesis integration with the pytest test runner. This plugin provider useful fixtures based on providers from Mimesis.
Stars: ✭ 46 (-2.13%)
Mutual labels:  pytest
Pytest Idapro
A pytest module for The Interactive Disassembler and IDAPython; Record and Replay IDAPython API, execute inside IDA or use mockups of IDAPython API.
Stars: ✭ 44 (-6.38%)
Mutual labels:  pytest
Jest Pytest
A Jest and Pytest integration made in heaven 💖
Stars: ✭ 28 (-40.43%)
Mutual labels:  pytest
mypy logo

pytest plugin for testing mypy types, stubs, and plugins

Build Status Checked with mypy Gitter

Installation

pip install pytest-mypy-plugins

Usage

Running

Plugin, after installation, is automatically picked up by pytest therefore it is sufficient to just execute:

pytest

Paths

The PYTHONPATH and MYPYPATH environment variables, if set, are passed to mypy on invocation. This may be helpful if you are testing a local plugin and need to provide an import path to it.

Be aware that when mypy is run in a subprocess (the default) the test cases are run in temporary working directories where relative paths such as PYTHONPATH=./my_plugin do not reference the directory which you are running pytest from. If you encounter this, consider invoking pytest with --mypy-same-process or make your paths absolute, e.g. PYTHONPATH=$(pwd)/my_plugin pytest.

You can also specify PYTHONPATH, MYPYPATH, or any other environment variable in env: section of yml spec:

- case: mypy_path_from_env
  main: |
    from pair import Pair

    instance: Pair
    reveal_type(instance)  # N: Revealed type is 'pair.Pair'
  env:
    - MYPYPATH=./pytest_mypy_plugins/tests/fixtures

What is a test case?

In general each test case is just an element in an array written in a properly formatted YAML file. On top of that, each case must comply to following types:

Property Type Description
case str Name of the test case, complies to [a-zA-Z0-9] pattern
main str Portion of the code as if written in .py file
files Optional[List[File]]=[]* List of extra files to simulate imports if needed
disable_cache Optional[bool]=False Set to true disables mypy caching
mypy_config Optional[Dict[str, Union[str, int, bool, float]]]={} Inline mypy configuration, passed directly to mypy as --config-file option
env Optional[Dict[str, str]]={} Environmental variables to be provided inside of test run
parametrized Optional[List[Parameter]]=[]* List of parameters, similar to @pytest.mark.parametrize
skip str Expression evaluated with following globals set: sys, os, pytest and platform

Appendix to pseudo types used above:

class File:
    path: str
    content: Optional[str] = None
Parameter = Mapping[str, Any]

Implementation notes:

  • main must be non-empty string that evaluates to valid Python code,
  • content of each of extra files must evaluate to valid Python code,
  • parametrized entries must all be the objects of the same type. It simply means that each entry must have exact same set of keys,
  • skip - an expression set in skip is passed directly into eval. It is advised to take a peek and learn about how eval works.

Example

1. Inline type expectations

# typesafety/test_request.yml
- case: request_object_has_user_of_type_auth_user_model
  main: |
    from django.http.request import HttpRequest
    reveal_type(HttpRequest().user)  # N: Revealed type is 'myapp.models.MyUser'
    # check that other fields work ok
    reveal_type(HttpRequest().method)  # N: Revealed type is 'Union[builtins.str, None]'
  files:
    - path: myapp/__init__.py
    - path: myapp/models.py
      content: |
        from django.db import models
        class MyUser(models.Model):
            pass

2. @parametrized

- case: with_params
  parametrized:
    - val: 1
      rt: builtins.int
    - val: 1.0
      rt: builtins.float
  main: |
    reveal_type({[ val }})  # N: Revealed type is '{{ rt }}'

3. Longer type expectations

- case: with_out
  main: |
    reveal_type('str')
  out: |
    main:1: note: Revealed type is 'builtins.str'

Options

mypy-tests:
  --mypy-testing-base=MYPY_TESTING_BASE
                        Base directory for tests to use
  --mypy-ini-file=MYPY_INI_FILE
                        Which .ini file to use as a default config for tests
  --mypy-same-process
                        Now, to help with various issues in django-stubs, it runs every single test in the subprocess mypy call.
                        Some debuggers cannot attach to subprocess, so enable this flag to make mypy check happen in the same process.
                        (Could cause cache issues)

Further reading

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].