Skip to content

Conversation

sgaist
Copy link
Contributor

@sgaist sgaist commented Oct 7, 2025

Add a warning when pytest.ini and pyproject.toml are present

The behaviour does not change however users will be notified that pytest.ini is selected over pyproject.toml and any configuration related to pytest it may contain.

Fixes #13330

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 7, 2025
@sgaist sgaist force-pushed the add-warning-on-pytest-ini-and-pyproject-presence branch from caf5ef7 to fce5184 Compare October 7, 2025 19:15
The behaviour does not change however users will be notified that pytest.ini is selected over pyproject.toml and any configuration related to pytest it may contain.
@sgaist sgaist force-pushed the add-warning-on-pytest-ini-and-pyproject-presence branch from fce5184 to 5ff1af4 Compare October 7, 2025 19:29
@sgaist
Copy link
Contributor Author

sgaist commented Oct 7, 2025

I am unsure what to do to satisfy codecov. Any hint would be appreciated.

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

I haven't thought yet whether we really want this, but in any case a couple of comments:

We should not emit a warning if pyproject.toml exists but without a pytest section. That's very common and expected and not ambiguous (please also add a test for this case).

Also, it will be better not to have the "should warn" logic in terminal.py, it shouldn't know about config stuff itself. Ideally (I think) the core config file search logic should indicate whether need to warn.

Doing so, Terminal does not need to know anything about the configuration files.
@sgaist
Copy link
Contributor Author

sgaist commented Oct 7, 2025

@bluetech I should have kept my original implementation which was following your suggestion minus the verification of the content of the pyproject.toml file.

I refactored the code following your suggestion.

@sgaist sgaist requested a review from bluetech October 7, 2025 21:16
Do it the other way around, check if the file suffix is ini rather than listing the possible names.
This will let users know exactly which files have been ignored in case multiple of them contain pytest configuration.
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Now the approach looks good to me, though I haven't reviewed the code in detail.

@nicoddemus I'll leave it to you to decide whether we want this :)

@nicoddemus
Copy link
Member

@nicoddemus I'll leave it to you to decide whether we want this :)

I think so, because having both configurations is confusing and error prone -- a warning would be welcome.

I will try to review this in the next few days, thanks folks!

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sgaist!

Left a few minor comments, please take a look!

 - Improved data type - Fixed multiple docstring - Cleaned up remainder config file check loop Co-authored-by: Bruno Oliveira <bruno@soliv.dev>
Copy link
Contributor Author

@sgaist sgaist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feebacks and suggestions !

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sgaist, LGTM!

I will let @bluetech do the final review and squash honors. 👍

@bluetech bluetech merged commit 288d573 into pytest-dev:main Oct 10, 2025
33 checks passed
@sgaist sgaist deleted the add-warning-on-pytest-ini-and-pyproject-presence branch October 10, 2025 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

3 participants