MonkeyType as a pytest plugin.

Overview

pytest-monkeytype

Build Status License PyPI Python PyPI Version PyPI Status PyPI Wheel

MonkeyType as a pytest plugin.

pip install pytest-monkeytype

# Generate annotations by running your pytest tests as usual:
py.test --monkeytype-output=./monkeytype.sqlite3

# Get a listing of modules annotated by monkeytype
monkeytype list-modules

# Generate a stub file for those annotations using monkeytype:
monkeytype stub some.module

# Apply these annotations directly
monkeytype apply some.module

This project is inspired by pytest-annotate

Comments
  • Fix CallTracer constructor call: #2

    Fix CallTracer constructor call: #2

    This PR aims to fix #2. I also encountered the same error as #2. CallTracer constructor added max_typed_dict_size as a positional argument since MonkeyType 20.4.1 or later.

    opened by thombashi 3
  • Trying to run pytest-monkeytype

    Trying to run pytest-monkeytype

    I have tried to use this plugin, it didn't work 🙂

    Here's the error message I got:

    » py.test --monkeytype-output=./monkeytype.sqlite3
    /Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pytest_benchmark/logger.py:44: PytestBenchmarkWarning: Can't compare. No benchmark files in '/Users/sobolev/Desktop/dramatiq/.benchmarks'. Can't load the previous benchmark.
      warner(PytestBenchmarkWarning(text))
    ================================ test session starts =================================
    platform darwin -- Python 3.7.7, pytest-3.10.1, py-1.8.1, pluggy-0.13.1
    benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
    rootdir: /Users/sobolev/Desktop/dramatiq, inifile: setup.cfg
    plugins: benchmark-3.2.3, cov-2.8.1, monkeytype-1.0.5
    collected 242 items                                                                  
    INTERNALERROR> Traceback (most recent call last):
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/_pytest/main.py", line 184, in wrap_session
    INTERNALERROR>     session.exitstatus = doit(config, session) or 0
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/_pytest/main.py", line 223, in _main
    INTERNALERROR>     config.hook.pytest_collection(session=session)
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
    INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
    INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
    INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
    INTERNALERROR>     return outcome.get_result()
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
    INTERNALERROR>     raise ex[1].with_traceback(ex[2])
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    INTERNALERROR>     res = hook_impl.function(*args)
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/_pytest/main.py", line 233, in pytest_collection
    INTERNALERROR>     return session.perform_collect()
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/_pytest/main.py", line 437, in perform_collect
    INTERNALERROR>     hook.pytest_collection_finish(session=self)
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
    INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
    INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
    INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
    INTERNALERROR>     return outcome.get_result()
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
    INTERNALERROR>     raise ex[1].with_traceback(ex[2])
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    INTERNALERROR>     res = hook_impl.function(*args)
    INTERNALERROR>   File "/Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pytest_monkeytype/plugin.py", line 40, in pytest_collection_finish
    INTERNALERROR>     sample_rate=None,
    INTERNALERROR> TypeError: __init__() missing 1 required positional argument: 'max_typed_dict_size'
    /Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pytest_benchmark/logger.py:44: PytestBenchmarkWarning: Not saving anything, no benchmarks have been run!
      warner(PytestBenchmarkWarning(text))
    

    Versions:

    » pytest --version
    This is pytest version 3.10.1, imported from /Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pytest.py
    setuptools registered plugins:
      pytest-benchmark-3.2.3 at /Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pytest_benchmark/plugin.py
      pytest-cov-2.8.1 at /Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pytest_cov/plugin.py
      pytest-monkeytype-1.0.5 at /Users/sobolev/Desktop/dramatiq/.venv/lib/python3.7/site-packages/pytest_monkeytype/plugin.py
    
    opened by sobolevn 1
  • Bugfix/trace logger

    Bugfix/trace logger

    I hit a problem with self.trace.logger being None so when I went to fix it, I noticed several other issues, such as logger not currently being part of the documented CallTracer interface.

    Hope these changes help!

    Also, is it true for MonkeyType that importing CallTracer should wait until after collection? I know that's how pytest-annotate does it but I think that might be due to the way PyAnnotate works which is different for MonkeyType. (I readily admit that I do not know much about gevent.)

    opened by wcooley 0
  • ERROR: Failed building wheel for pytest-monkeytype

    ERROR: Failed building wheel for pytest-monkeytype

    $ python --version
    Python 3.8.10
    

    Trying: pip install pytest-monkeytype

    output

      ERROR: Command errored out with exit status 1:
       command: /home/jonathan/develop/selenium-python-helium/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-sfwdi49o/pytest-monkeytype/setup.py'"'"'; __file__='"'"'/tmp/pip-install-sfwdi49o/pytest-monkeytype/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-ylsggp4t
           cwd: /tmp/pip-install-sfwdi49o/pytest-monkeytype/
      Complete output (6 lines):
      usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
         or: setup.py --help [cmd1 cmd2 ...]
         or: setup.py --help-commands
         or: setup.py cmd --help
      
      error: invalid command 'bdist_wheel'
      ----------------------------------------
      ERROR: Failed building wheel for pytest-monkeytype
    
    opened by jonathanelscpt 1
  • No hook for custom configuration

    No hook for custom configuration

    I need to configure MonkeyType but this plugin does not allow to provide custom configuration. Usually pytest plugins can be configured using fixtures.

    opened by thedrow 0
Owner
Marius van Niekerk
Full stack data scientist
Marius van Niekerk
Unbearably fast O(1) runtime type-checking in pure Python.

Look for the bare necessities, the simple bare necessities. Forget about your worries and your strife. — The Jungle Book.

beartype 1.4k Jan 01, 2023
flake8 plugin which checks that typing imports are properly guarded

flake8-typing-imports flake8 plugin which checks that typing imports are properly guarded installation pip install flake8-typing-imports flake8 codes

Anthony Sottile 50 Nov 01, 2022
❄️ A flake8 plugin to help you write better list/set/dict comprehensions.

flake8-comprehensions A flake8 plugin that helps you write better list/set/dict comprehensions. Requirements Python 3.6 to 3.9 supported. Installation

Adam Johnson 398 Dec 23, 2022
Silence mypy by adding or removing code comments

mypy-silent Automatically add or remove # type: ignore commends to silence mypy. Inspired by pylint-silent Why? Imagine you want to add type check for

Wu Haotian 8 Nov 30, 2022
Tool to check the completeness of MANIFEST.in for Python packages

check-manifest Are you a Python developer? Have you uploaded packages to the Python Package Index? Have you accidentally uploaded broken packages with

Marius Gedminas 270 Dec 26, 2022
The mypy playground. Try mypy with your web browser.

mypy-playground The mypy playground provides Web UI to run mypy in the sandbox: Features Web UI and sandbox for running mypy eas

Yusuke Miyazaki 57 Jan 02, 2023
Flake8 plugin for managing type-checking imports & forward references

flake8-type-checking Lets you know which imports to put in type-checking blocks. For the imports you've already defined inside type-checking blocks, i

snok 67 Dec 16, 2022
Mypy plugin and stubs for SQLAlchemy

Pythonista Stubs Stubs for the Pythonista iOS API. This allows for better error detection and IDE / editor autocomplete. Installation and Usage pip in

Dropbox 521 Dec 29, 2022
A plugin for flake8 integrating Mypy.

flake8-mypy NOTE: THIS PROJECT IS DEAD It was created in early 2017 when Mypy performance was often insufficient for in-editor linting. The Flake8 plu

Łukasz Langa 103 Jun 23, 2022
Utilities for pycharm code formatting (flake8 and black)

Pycharm External Tools Extentions to Pycharm code formatting tools. Currently supported are flake8 and black on a selected code block. Usage Flake8 [P

Haim Daniel 13 Nov 03, 2022
Type annotations builder for boto3 compatible with VSCode, PyCharm, Emacs, Sublime Text, pyright and mypy.

mypy_boto3_builder Type annotations builder for boto3-stubs project. Compatible with VSCode, PyCharm, Emacs, Sublime Text, mypy, pyright and other too

Vlad Emelianov 2 Dec 05, 2022
flake8 plugin that integrates isort

Flake8 meet isort Use isort to check if the imports on your python files are sorted the way you expect. Add an .isort.cfg to define how you want your

Gil Forcada Codinachs 139 Nov 08, 2022
Check for python builtins being used as variables or parameters

Flake8 Builtins plugin Check for python builtins being used as variables or parameters. Imagine some code like this: def max_values(list, list2):

Gil Forcada Codinachs 98 Jan 08, 2023
Mylint - My really simple rendition of how a linter works.

mylint My really simple rendition of how a linter works. This original version was written for my AST article. Since then I've added tests and turned

Tushar Sadhwani 2 Dec 29, 2021
Tools for improving Python imports

imptools Tools for improving Python imports. Installation pip3 install imptools Overview Detailed docs import_path Import a module from any path on th

Danijar Hafner 7 Aug 07, 2022
open source tools to generate mypy stubs from protobufs

mypy-protobuf: Generate mypy stub files from protobuf specs We just released a new major release mypy-protobuf 2. on 02/02/2021! It includes some back

Dropbox 527 Jan 03, 2023
A static type analyzer for Python code

pytype - 🦆 ✔ Pytype checks and infers types for your Python code - without requiring type annotations. Pytype can: Lint plain Python code, flagging c

Google 4k Dec 31, 2022
Flake8 extension for checking quotes in python

Flake8 Extension to lint for quotes. Major update in 2.0.0 We automatically encourage avoiding escaping quotes as per PEP 8. To disable this, use --no

Zachary Heller 157 Dec 13, 2022
Pylint plugin for improving code analysis for when using Django

pylint-django About pylint-django is a Pylint plugin for improving code analysis when analysing code using Django. It is also used by the Prospector t

Python Code Quality Authority 544 Jan 06, 2023
Flake8 plugin for managing type-checking imports & forward references

flake8-type-checking Lets you know which imports to put in type-checking blocks. For the imports you've already defined inside type-checking blocks, i

snok 67 Dec 16, 2022