Skip to content

MAINT Replace setup_module by pytest fixtures#28475

Merged
thomasjpfan merged 5 commits intoscikit-learn:mainfrom
lesteve:replace-setup-module-by-pytest-fixture
Feb 22, 2024
Merged

MAINT Replace setup_module by pytest fixtures#28475
thomasjpfan merged 5 commits intoscikit-learn:mainfrom
lesteve:replace-setup-module-by-pytest-fixture

Conversation

@lesteve
Copy link
Copy Markdown
Member

@lesteve lesteve commented Feb 20, 2024

Context #28461.

Using pytest fixtures avoids the Pytest 8.0.1 bug pytest-dev/pytest#12011 and is slightly more readable by not having to use module globals.

This is also recommended by Pytest in https://docs.pytest.org/en/stable/xunit_setup.html

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 20, 2024

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 7104827. Link to the linter CI: here

@betatim
Copy link
Copy Markdown
Member

betatim commented Feb 20, 2024

This looks uncontroversial to me.

One thing to think about is https://docs.pytest.org/en/6.2.x/tmpdir.html instead of using tempfile. I'm not sure of the pros and cons, but I thought it is worth pointing out that pytest has infrastructure for temporary files and directories.

@lesteve
Copy link
Copy Markdown
Member Author

lesteve commented Feb 20, 2024

Yeah I agree, that this was probably some old code that was inherited from the nose days and not touched in a while, I will look into using Pytest tmp_path_factory fixture and see if that simplifies the code even further.

Copy link
Copy Markdown
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM. Nice cleanup !

data_dir = tmp_path_factory.mktemp("scikit_learn_empty_test")

global SCIKIT_LEARN_DATA, SCIKIT_LEARN_EMPTY_DATA, LFW_HOME
yield data_dir
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you can now use return

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can but, I'd rather always use yield so I don't have to think "when should I use yield, when should I use return" ...

FWIW Pytest doc also recommends using yield fixtures: https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#yield-fixtures-recommended

@jeremiedbb
Copy link
Copy Markdown
Member

@betatim are you happy with the latest changes ?

@lesteve lesteve mentioned this pull request Feb 22, 2024
Copy link
Copy Markdown
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

LGTM

@thomasjpfan thomasjpfan merged commit 93f6ce9 into scikit-learn:main Feb 22, 2024
@lesteve lesteve deleted the replace-setup-module-by-pytest-fixture branch February 23, 2024 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants