Issue #183 resolved

AttributeError: test command fails with NoneType object has no attribute 'run'

Jason R. Coombs
created an issue

Arfrever Frehtes Taifersar Arahesis reports that the recent change to support custom test loaders (d9932598b86f) now causes AttributeErrors when no testLoader is supplied on Python 2.6 and 3.1.

Comments (10)

  1. Jason R. Coombs reporter

    Arfrever suggested this patch which almost surely would work, but it would mask the purpose of the code. Especially when supporting cross-python compatibility, I would prefer to have a wrapped to capture the compatibility logic (and thus describe when the compatibility logic is safe to remove, in this case after Python 2.6/3.1 is dropped).

  2. Arfrever Frehtes Taifersar Arahesis

    (I mentioned only Python 3.1 on IRC.)

    Content of my patch for historical reference:

    diff --git a/setuptools/command/ b/setuptools/command/
    --- a/setuptools/command/
    +++ b/setuptools/command/
    @@ -158,11 +158,12 @@
                     list(map(sys.modules.__delitem__, del_modules))
    -        unittest.main(
    -            None, None, [unittest.__file__]+self.test_args,
    -            testLoader=self._resolve_as_ep(self.test_loader),
    -            testRunner=self._resolve_as_ep(self.test_runner),
    -        )
    +        kwargs = {}
    +        if self.test_loader is not None:
    +            kwargs["testLoader"] = self._resolve_as_ep(self.test_loader)
    +        if self.test_runner is not None:
    +            kwargs["testRunner"] = self._resolve_as_ep(self.test_runner)
    +        unittest.main(None, None, [unittest.__file__]+self.test_args, **kwargs)
         def _resolve_as_ep(val):
  3. Arfrever Frehtes Taifersar Arahesis

    369f6f90f696 does not work:

    Traceback (most recent call last):
      File "", line 217, in <module>
        dist = setuptools.setup(**setup_params)
      File "/usr/lib64/python3.1/distutils/", line 149, in setup
      File "/usr/lib64/python3.1/distutils/", line 919, in run_commands
      File "/usr/lib64/python3.1/distutils/", line 938, in run_command
      File "", line 68, in run
      File "/tmp/setuptools/setuptools/command/", line 146, in run
      File "/tmp/setuptools/setuptools/command/", line 127, in with_project_on_sys_path
      File "/tmp/setuptools/setuptools/command/", line 167, in run_tests
      File "/tmp/setuptools/setuptools/", line 52, in unittest_main
        return unittest.main(*args, **kwargs)
      File "/usr/lib64/python3.1/", line 1573, in __init__
      File "/usr/lib64/python3.1/", line 1618, in runTests
        self.result =
    AttributeError: 'TestLoader' object has no attribute 'run'
  4. marcio_

    It appears this doesn't fix the same problem for Python 2.6. It also needs to translate testRunner==None to TextTestRunner.

    Traceback (most recent call last):
      File "", line 133, in <module>
        'Topic :: Software Development :: Libraries :: Python Modules',
      File "C:\Python26\lib\distutils\", line 152, in setup
      File "C:\Python26\lib\distutils\", line 975, in run_commands
      File "C:\Python26\lib\distutils\", line 995, in run_command
      File "build\bdist.win32\egg\setuptools\command\", line 142, in run
      File "build\bdist.win32\egg\setuptools\command\", line 122, in with_project_on_sys_path
      File "build\bdist.win32\egg\setuptools\command\", line 163, in run_tests
      File "C:\Python26\lib\", line 817, in __init__
      File "C:\Python26\lib\", line 861, in runTests
        result =
    AttributeError: 'NoneType' object has no attribute 'run'
  5. Jason R. Coombs reporter

    @marciof If I trust the comments above (and I don't fully), the Travis-CI tests demonstrate that the commands run fine on Python 2.6. Of course, since then, the test runner has been converted to pytest, so it may no longer be the case that the invocation of test under Python 2.6 exercises the code in question. Still, at the time, apparently the tests were running under Python 2.6. Is it possible that the functionality was released in a patch version of Python 2.6 or that you're running a pre-release version of Python 2.6? What (full) version of Python 2.6 do you have?

  6. marcio_

    Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32. This is on Windows 8.1 32-bit with setuptools 18.2. I previously didn't have this problem for my hobby project, and it only appeared after upgrading setuptools, Windows and reinstalling Python 2.6 on a new PC (I don't remember the previous exact versions). I want to test this same combination on Linux, but I currently don't have easy access to do that.

  7. Log in to comment