typeddjango / pytest-mypy-plugins

pytest plugin for testing mypy types, stubs, and plugins
https://pypi.org/project/pytest-mypy-plugins/
MIT License
100 stars 26 forks source link

Add Mypy configuration through root "pyproject.toml" file #135

Open Delgan opened 10 months ago

Delgan commented 10 months ago

Hi!

This is a proposal to fix #133.

This offers a way to use Mypy configuration specific to tests without needing the --mypy-pyproject-toml-file command line argument. Instead, users can define a [tool.pytest-mypy-plugins.mypy-config] table in their repository's pyproject.toml file.

This approach addresses two issues:

The order of precedence for Mypy configuration is as follows, with each subsequent option taking precedence over the previous ones if it exists:

  1. Use configuration from [tool.pytest-mypy-plugins.mypy-config] in the root pyproject.toml as default.
  2. Override default with options from --mypy-pyproject-toml-file or --mypy-ini-file if provided.
  3. Override again with config_mypy section in a test if present.

I hope this process isn't too convoluted. Please let me know if you prefer a different approach. I made slight modifications to the join_toml_configs() function to implement the rules mentioned above. Additionally, I can add more unit tests if necessary.

sobolevn commented 10 months ago

Thanks a lot!

Delgan commented 10 months ago

@sobolevn I updated the PR according to your comments. :+1:

Two remarks waiting for your opinion: