Skip to main content

Test mypy plugins, stubs, custom types.

Project description

mypy_test

Test mypy plugins, stubs, custom types.

Features:

  • Flexible: supports every feature supported by mypy, does not enforce a project structure.
  • Fast: mypy gets run only once for all files at once. Also, no patching, no config generation.
  • Easy to learn: run mypy_test with the same arguments as you would run mypy, and it just works.
  • Lightweight: no dependencies except mypy.
python3 -m pip install mypy-test

Usage

  1. Write a file you want to test, add comments to the lines you expect to fail:

    a = 1
    reveal_type(a)  # R: builtins.int
    
  2. Run the tool:

    python3 -m mypy_test example.py
    

Writing the comments

  • The comments have the following format: SEVERITY: MESSAGE.
  • Severity is a one-letter violation severity as reported by mypy.
    • F for "fatal"
    • E for "error"
    • W for "warning"
    • N for "note"
    • R is a shorthand for N: Revealed type is "..."
  • Comment can be on the same line as the violation or on the line before.

Example:

var = 1.1
reveal_type(var)  # R: builtins.float

# E: Incompatible types in assignment (expression has type "str", variable has type "float")
var = ""

Tips:

  • The fastest way to know the severity and the message is to run mypy_test on the code and then copy-paste the resulting message.
  • Make separate functions for every test case, so it can have a nice description and a clean namespace.
  • Place all test files into one directory. For example, /types/ or /tests/types/.

Alternatives

  • pytest-mypy-plugins - pytest plugin, test cases described in a YAML file.
  • pytest-mypy-testing - pytest plugin, tests are described like pytest test cases (but they actually don't get run).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mypy-test-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

mypy_test-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file mypy-test-0.1.0.tar.gz.

File metadata

  • Download URL: mypy-test-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for mypy-test-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b7b32a4eb93368377eb77ea41e69971d400b968536afd7000400cfea57a9aa0
MD5 5001ab3036e915bcdcb5a89004b8ecbf
BLAKE2b-256 13bd6233b2b511df5efc8efce76c8eba2f5cda7dcd3061b6b828792f623e474e

See more details on using hashes here.

File details

Details for the file mypy_test-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mypy_test-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for mypy_test-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c5faf123765c70634243fc18096260b9428ec5187bb37002f56c3ef9a9daac6
MD5 0d81c928ec41a5b8278c5ad59359789b
BLAKE2b-256 846b50ef2bde0502086147b9f389c72d0e0977089f02fe5b4e631fc3526187d1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page