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 (7)

  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/test.py b/setuptools/command/test.py
    --- a/setuptools/command/test.py
    +++ b/setuptools/command/test.py
    @@ -158,11 +158,12 @@
                             del_modules.append(name)
                     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)
    
         @staticmethod
         def _resolve_as_ep(val):
    
  3. Arfrever Frehtes Taifersar Arahesis

    369f6f90f696 does not work:

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