GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test_inspect fails with `--forever` argument · Issue #107446 · python/cpython

test_inspect fails with --forever argument #107446

New issue
Copy link
New issue
Copy link
Closed
Closed
test_inspect fails with --forever argument#107446
Copy link
Assignees
gaogaotiantiankumaraditya303
Labels
3.13only security fixesonly security fixesrelease-blockertestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@Eclips4
Eclips4
opened on Jul 29, 2023
Issue body actions

Traceback:

...many lines...
test_unwrap_several (test.test_inspect.TestUnwrap.test_unwrap_several) ... ok

======================================================================
ERROR: test_class_with_method_from_other_module (test.test_inspect.TestBuggyCases.test_class_with_method_from_other_module)       
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\test\test_inspect.py", line 992, in test_class_with_method_from_other_module  
    self.assertIn("correct", inspect.getsource(inspect_actual.A))
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\inspect.py", line 1317, in getsource
    lines, lnum = getsourcelines(object)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\inspect.py", line 1299, in getsourcelines
    lines, lnum = findsource(object)
                  ^^^^^^^^^^^^^^^^^^
  File "C:\Users\KIRILL-1\CLionProjects\cpython\Lib\inspect.py", line 1134, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

----------------------------------------------------------------------
Ran 286 tests in 2.392s

FAILED (errors=1)
test test_inspect failed
test_inspect failed (1 error)

== Tests result: FAILURE ==

1 test OK.

1 test failed:
    test_inspect

Total duration: 7.2 sec
Tests result: FAILURE

Triend on current main.

Linked PRs

  • gh-107446: Fix test_inspect.test_class_with_method_from_other_module under --forever #107451

Activity

  1. Eclips4
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jul 29, 2023
  2. AlexWaygood
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    on Jul 29, 2023
  3. Eclips4 commented on Jul 29, 2023

    @Eclips4
    Eclips4
    on Jul 29, 2023
    MemberAuthor
    More actions

    bisected to #106968
    cc @gaogaotiantian

  4. gaogaotiantian
    self-assigned this
    on Jul 29, 2023
  5. Eclips4 commented on Jul 29, 2023

    @Eclips4
    Eclips4
    on Jul 29, 2023
    MemberAuthor
    More actions

    Interesting. If we replace tempfile.TemporaryDirectory with something like that, error will gone.

        def test_class_with_method_from_other_module(self):
            tempdir = TESTFN + '_other_module_dir'
            os.mkdir(tempdir)
            with open(os.path.join(tempdir, 'inspect_actual%spy' % os.extsep),
                      'w', encoding='utf-8') as f:
                f.write(textwrap.dedent("""
                                    import inspect_other
                                    class A:
                                        def f(self):
                                            pass
                                    class A:
                                        def f(self):
                                            pass  # correct one
                                    A.f = inspect_other.A.f
                                    """))
            with open(os.path.join(tempdir, 'inspect_other%spy' % os.extsep),
                    'w', encoding='utf-8') as f:
                f.write(textwrap.dedent("""
                                    class A:
                                        def f(self):
                                            pass
                                    """))
            with DirsOnSysPath(tempdir):
                import inspect_actual
                self.assertIn("correct", inspect.getsource(inspect_actual.A))
            shutil.rmtree(tempdir)
  6. gaogaotiantian commented on Jul 29, 2023

    @gaogaotiantian
    gaogaotiantian
    on Jul 29, 2023
    Member
    More actions

    The inspect_actual module was loaded then the temp dir is removed under --forever, so the source file is no where to be found. I'll do a PR soon.

  7. gaogaotiantian commented on Jul 29, 2023

    @gaogaotiantian
    gaogaotiantian
    on Jul 29, 2023
    Member
    More actions

    I chose to simply do sys.modules.pop("inspect_actual"). We can try to fix the temp dir, but I do like the context of tempfile.TemporaryDirectory(), I think it's cleaner than TESTFN. However, I'm not opposed to use the same dir for the module.

    Reacted by Kirill Podoprigora
  8. Eclips4 commented on Jul 30, 2023

    @Eclips4
    Eclips4
    on Jul 30, 2023
    MemberAuthor
    More actions

    Sure, solution with sys.modules.pop(...) more appropriate.

  9. kumaraditya303
    added
    release-blocker
    3.13only security fixesonly security fixes
    on Aug 3, 2023
  10. ezio-melotti
    added this to Release and Deferred blockers 🚫on Aug 3, 2023
  11. github-project-automation
    moved this to Todo in Release and Deferred blockers 🚫on Aug 3, 2023
  12. kumaraditya303
    self-assigned this
    on Aug 3, 2023
  13. kumaraditya303
    added a commit that references this issue on Aug 3, 2023

    gh-107446: Fix test_inspect.test_class_with_method_from_other_module …

    14fbd4e
  14. kumaraditya303
    closed this as completedon Aug 3, 2023
  15. github-project-automation
    moved this from Todo to Done in Release and Deferred blockers 🚫on Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gaogaotiantian
    gaogaotiantian
  • @kumaraditya303
    kumaraditya303

Labels

3.13only security fixesonly security fixesrelease-blockertestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • Release and Deferred blockers 🚫
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.