Add Mypy configuration through root "pyproject.toml" file
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:
- Avoids the need for an extra file in the repository to store Mypy test configuration.
- Ensures that
pytestcan be invoked from any location (this is not possible when--mypy-pyproject-toml-fileis specified via theaddoptsconfiguration, as paths are resolved relative to the current working directory).
The order of precedence for Mypy configuration is as follows, with each subsequent option taking precedence over the previous ones if it exists:
- Use configuration from
[tool.pytest-mypy-plugins.mypy-config]in the rootpyproject.tomlas default. - Override default with options from
--mypy-pyproject-toml-fileor--mypy-ini-fileif provided. - Override again with
config_mypysection 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.
Thanks a lot!
@sobolevn I updated the PR according to your comments. :+1:
Two remarks waiting for your opinion:
- maybe I should rename the
mypy-configtable toconfig-mypyfor consistency with the existing inline field. - I could also add tests for
join_ini_configs()but I don't know what are your preferences regarding theassert_file_contents()utils function (should it be duplicated, or what is the common file where I should move it).