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

RecursionError: maximum recursion depth exceeded while calling a Python object when running simple UnitTest due to GitPython unittests also being included #1049

Open
jmartens opened this issue Aug 24, 2020 · 3 comments

Comments

@jmartens
Copy link

@jmartens jmartens commented Aug 24, 2020

While writing a unittest for a framework I ran into RecursionErrors:

I was able to reproduce it with this minimal test case:

from unittest import TestCase
from git import Repo
from tempfile import NamedTemporaryFile, TemporaryDirectory


class TestRunner(TestCase):

    def test_check_repo(self):

        # Normal repository...
        with TemporaryDirectory() as repo_dir:
            repo = Repo.init(repo_dir, bare=False)

            # ... with untracked files
            with NamedTemporaryFile(dir=repo_dir, mode="r+", delete=False) as file:
                file.file.writelines(["This is a test file..."])

            # Add initial commit, so we can tag
            repo.index.add([file.name])
            repo.index.commit('Test commit for unittest')

If I run above example like:

Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python38\lib\unittest\__main__.py", line 18, in <module>
    main(module=None)
  File "C:\Program Files\Python38\lib\unittest\main.py", line 101, in __init__
    self.runTests()
  File "C:\Program Files\Python38\lib\unittest\main.py", line 271, in runTests
    self.result = testRunner.run(self.test)
  File "C:\Program Files\Python38\lib\unittest\runner.py", line 176, in run
    test(result)
  File "C:\Program Files\Python38\lib\unittest\suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "C:\Program Files\Python38\lib\unittest\suite.py", line 122, in run
    test(result)
  File "C:\Program Files\Python38\lib\unittest\suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "C:\Program Files\Python38\lib\unittest\suite.py", line 122, in run
    test(result)
  File "C:\Program Files\Python38\lib\unittest\case.py", line 736, in __call__
    return self.run(*args, **kwds)
  File "C:\Program Files\Python38\lib\unittest\case.py", line 684, in run
    self._feedErrorsToResult(result, outcome.errors)
  File "C:\Program Files\Python38\lib\unittest\case.py", line 602, in _feedErrorsToResult
    result.addError(test, exc_info)
  File "C:\Program Files\Python38\lib\unittest\runner.py", line 67, in addError
    super(TextTestResult, self).addError(test, err)
  File "C:\Program Files\Python38\lib\unittest\result.py", line 17, in inner
    return method(self, *args, **kw)
  File "C:\Program Files\Python38\lib\unittest\result.py", line 115, in addError
    self.errors.append((test, self._exc_info_to_string(err, test)))
  File "C:\Program Files\Python38\lib\unittest\result.py", line 185, in _exc_info_to_string
    tb_e = traceback.TracebackException(
  File "C:\Program Files\Python38\lib\traceback.py", line 493, in __init__
    context = TracebackException(
  File "C:\Program Files\Python38\lib\traceback.py", line 493, in __init__
    context = TracebackException(
  File "C:\Program Files\Python38\lib\traceback.py", line 493, in __init__
    context = TracebackException(
  [Previous line repeated 485 more times]
  File "C:\Program Files\Python38\lib\traceback.py", line 476, in __init__
    _seen.add(id(exc_value))
RecursionError: maximum recursion depth exceeded while calling a Python object

As soon as I remove the line that actually commits the recursion errors disappear so I am I guessing some uncaught exception is thrown somewhere when doing a commit.

@Byron Byron added the acknowledged label Sep 1, 2020
@Byron
Copy link
Member

@Byron Byron commented Sep 1, 2020

Maybe there is more to it, but should I expect the code above to run if pasted into a python file inside of the GitPython repository, and run with python 3.8.2?

It cannot find 'TestCase'.

@jmartens
Copy link
Author

@jmartens jmartens commented Sep 1, 2020

No this is a test case taken from my project, so you should need to create a new project which uses GitPython, create a test case in there and invoke it.

You might need some additional import statements as used in normal unittesting like from unittest import TestCase.

I have updated my example.

@Byron Byron added cannot reproduce and removed acknowledged labels Sep 2, 2020
@Byron
Copy link
Member

@Byron Byron commented Sep 2, 2020

Thank you!
Since I am pretty sure that GitPython doesn't include tests in production code, I would hope the issue goes away in a more minimal example that isn't tied to a particular codebase anymore.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.