Skip to content

Add plugin configuration through pyproject.toml? #133

Open
@Delgan

Description

@Delgan

Hi!

I need a dedicated mypy.ini configuration for tests run by pytest-mypy-plugins. This configuration includes parameters like force_uppercase_builtins = true, which are very useful for unit tests but irrelevant for the entire project.

Currently, I can create a separate mypy-tests.ini file and run pytest with the --mypy-ini-file option. To avoid typing this every time, I can add addopts = "--mypy-ini-file=mypy-tests.ini" to my pytest.ini configuration.

However, there is a drawback to this approach: the path is resolved relative to the current working directory, not to pytest.ini. This can lead to surprising behavior, where test output changes depending on where the pytest command was executed. For example, running tests from outside the project's root folder may cause Mypy tests to fail (because it won't use the required mypy-tests.ini file) although all others ran seamlessly.

I'd like my tests to be robust in such cases. Pytest itself works flawlessly, so I believe plugins should too. I assume resolving the --mypy-ini-file path relative to the "rootdir" is not acceptable for a command-line option. Therefore, it seems appropriate to allow configuration via a file and, in this case, resolve the paths relative to that file. We could even imagine a "override mypy config" entry to avoid the additional mypy-tests.ini file in my scenario.

What are your thoughts on this?

I've noticed that pytest-mypy-plugins already depends on tomlkit, so I assume implementing this shouldn't be overly complicated.
However, I understand if you prefer not to add complexity to the plugin configuration in this way. Yet, If you're open to the idea, I'd be happy to contribute with a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions