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

os.chdir in unittest's test case causes RecursionError on Windows #90145

Closed
tos-kamiya mannequin opened this issue Dec 5, 2021 · 6 comments
Closed

os.chdir in unittest's test case causes RecursionError on Windows #90145

tos-kamiya mannequin opened this issue Dec 5, 2021 · 6 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tos-kamiya
Copy link
Mannequin

tos-kamiya mannequin commented Dec 5, 2021

BPO 45987
Nosy @serhiy-storchaka, @eryksun, @tos-kamiya
Files
  • test_chdir_fails.py
  • FF2dfQ_acAc497b.png
  • test_chdir_wo_fail.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-12-05.23:18:44.958>
    created_at = <Date 2021-12-05.14:25:09.030>
    labels = ['invalid', 'type-bug', 'library', '3.9']
    title = "os.chdir in unittest's test case causes RecursionError on Windows"
    updated_at = <Date 2021-12-05.23:51:21.507>
    user = 'https://github.com/tos-kamiya'

    bugs.python.org fields:

    activity = <Date 2021-12-05.23:51:21.507>
    actor = 'tos-kamiya'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-12-05.23:18:44.958>
    closer = 'tos-kamiya'
    components = ['Library (Lib)']
    creation = <Date 2021-12-05.14:25:09.030>
    creator = 'tos-kamiya'
    dependencies = []
    files = ['50476', '50477', '50478']
    hgrepos = []
    issue_num = 45987
    keywords = []
    message_count = 6.0
    messages = ['407711', '407732', '407735', '407754', '407757', '407761']
    nosy_count = 3.0
    nosy_names = ['serhiy.storchaka', 'eryksun', 'tos-kamiya']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45987'
    versions = ['Python 3.9']

    @tos-kamiya
    Copy link
    Mannequin Author

    tos-kamiya mannequin commented Dec 5, 2021

    When I was writing unit tests, I noticed that os.chdir in the unittest test case failed with RecursionError.

    It seems to work fine on Ubuntu 20.04, but fails on Windows 10 (might fail on macOS).

    The attached file is a minimal code to reproduce this.

    When I run it, I got an error message as follows

    PS C:\Users\toshihiro\tmp> python .\test_chdir_fails.py
    Traceback (most recent call last):
      File "C:\Users\toshihiro\tmp\test_chdir_fails.py", line 11, in <module>
        unittest.main()
      File "C:\Users\toshihiro\AppData\Local\Programs\Python\Python39\lib\unittest\main.py", line 101, in __init__
        self.runTests()
    (snip)
      File "C:\Users\toshihiro\AppData\Local\Programs\Python\Python39\lib\traceback.py", line 493, in __init__
        context = TracebackException(
      [Previous line repeated 487 more times]
    RecursionError: maximum recursion depth exceeded
    PS C:\Users\toshihiro\tmp>
    

    The version of python was:
    Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32

    Regards,

    @tos-kamiya tos-kamiya mannequin added type-crash A hard crash of the interpreter, possibly with a core dump 3.9 only security fixes stdlib Python modules in the Lib dir labels Dec 5, 2021
    @AlexWaygood AlexWaygood added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 5, 2021
    @serhiy-storchaka
    Copy link
    Member

    What is (snip)?

    @eryksun
    Copy link
    Contributor

    eryksun commented Dec 5, 2021

    Windows opens the working directory without delete sharing, so trying to delete it fails with a PermissionError for ERROR_SHARING_VIOLATION (winerror 32).

    I discussed a modified version of the _rmtree() method in msg377358. The proposed version would try to reset the permissions in the first pass, recur once, and then give up because the permission error cannot be handled.

    @tos-kamiya
    Copy link
    Mannequin Author

    tos-kamiya mannequin commented Dec 5, 2021

    Sorry, the "(snip)" means that it was omitted because it was too long.
    I' ll attach a screenshot.

    @tos-kamiya
    Copy link
    Mannequin Author

    tos-kamiya mannequin commented Dec 5, 2021

    Thank you, eryksun, for pointing out the cause of the problem. I have modified the test script and it can now be run on Windows.

    The attached file is a revised version of the reproduction script, which reflects the modifications made to the test script to prevent the error.

    @tos-kamiya tos-kamiya mannequin closed this as completed Dec 5, 2021
    @tos-kamiya tos-kamiya mannequin added the invalid label Dec 5, 2021
    @tos-kamiya tos-kamiya mannequin closed this as completed Dec 5, 2021
    @tos-kamiya tos-kamiya mannequin added the invalid label Dec 5, 2021
    @tos-kamiya
    Copy link
    Mannequin Author

    tos-kamiya mannequin commented Dec 5, 2021

    I think it may be difficult to understand the error message that deleting a directory causes "RecursionError or stack overflow", though.

    I hope the issue reported as msg377358 will be resolved in some way.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants