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

pytest._pathlib.import_path should pass absolute paths on Python>=3.8 <3.10 #8918

Closed
graingert opened this issue Jul 17, 2021 · 2 comments
Closed
Labels
type: refactoring internal improvements to the code

Comments

@graingert
Copy link
Member

graingert commented Jul 17, 2021

In https://bugs.python.org/issue44070, spec_from_file_location() has changed its behaviour so that the responsibility of passing absolute paths is on the caller between 3.8 and 3.10

So something like this is needed:

    if (3, 8) <= sys.version_info[:2] < (3, 10) and not os.path.isabs(fn):
        # module.__spec__.__file__ is supposed to be absolute in py3.8+
        # importlib.util.spec_from_file_location does this automatically from
        # 3.10+
        # This was backported to 3.8 and 3.9, but then reverted in 3.8.11 and
        # 3.9.6
        # See https://twistedmatrix.com/trac/ticket/10230
        # and https://bugs.python.org/issue44070
        fn = os.path.join(os.getcwd(), fn)

spec = importlib.util.spec_from_file_location(module_name, str(path))

@Zac-HD Zac-HD added the type: refactoring internal improvements to the code label Jul 26, 2021
@sgaist
Copy link
Contributor

sgaist commented Sep 25, 2021

Hi,

I would like to take care of this one for Hacktoberfest.

@nicoddemus
Copy link
Member

In the end we verified this is not needed, see: #9140 (comment)

Thanks @graingert!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactoring internal improvements to the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants