Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change pytest import mode to importlib #4950

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

GvS666
Copy link
Contributor

@GvS666 GvS666 commented Mar 29, 2024

Description

Change pytest import mode to importlib

Checklist:

  • I've made sure that tests are updated accordingly (especially if adding or updating a template option)
  • I've updated the documentation or confirm that my change doesn't require any updates

Rationale

Based on https://docs.pytest.org/en/7.1.x/explanation/goodpractices.html#choosing-an-import-mode :

"For historical reasons, pytest defaults to the prepend import mode instead of the importlib import mode we recommend for new projects. The reason lies in the way the prepend mode works:

Since there are no packages to derive a full package name from, pytest will import your test files as top-level modules. The test files in the first example (src layout) would be imported as test_app and test_view top-level modules by adding tests/ to sys.path.

This results in a drawback compared to the import mode importlib: your test files must have unique names. (...)
The importlib import mode does not have any of the drawbacks above, because sys.path is not changed when importing test modules.
"

Copy link
Collaborator

@foarsitter foarsitter left a comment

Choose a reason for hiding this comment

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

Thanks @GvS666

@foarsitter foarsitter merged commit 9956f2b into cookiecutter:master Apr 2, 2024
13 checks passed
@traviswaelbro
Copy link

It's worth noting that this currently results in a pytest output issue, where assert failures are not having their differences output as expected. For reference, see pytest-dev/pytest#12659.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants