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

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

Closed
bb-migration opened this Issue Apr 6, 2014 · 10 comments

Comments

Projects
None yet
1 participant
@bb-migration

bb-migration commented Apr 6, 2014

Originally reported by: jaraco (Bitbucket: jaraco, GitHub: jaraco)


@Arfrever 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.


@bb-migration

This comment has been minimized.

bb-migration commented Apr 6, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


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

@bb-migration

This comment has been minimized.

bb-migration commented Apr 6, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


I see now that Python 2.6 is not implicated (as is also evidenced by the Travis test runs). Only Python 3.1 is affected by this edge case.

@bb-migration

This comment has been minimized.

bb-migration commented Apr 6, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Wrap unittest.main in a compatibility wrapper for Python 3.1 compatibility. Fixes #183

@bb-migration

This comment has been minimized.

bb-migration commented Apr 7, 2014

Original comment by arfrever (Bitbucket: arfrever, GitHub: arfrever):


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

@bb-migration

This comment has been minimized.

bb-migration commented Apr 7, 2014

Original comment by arfrever (Bitbucket: arfrever, GitHub: arfrever):


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'
@bb-migration

This comment has been minimized.

bb-migration commented Apr 7, 2014

Original comment by arfrever (Bitbucket: arfrever, GitHub: arfrever):


Fixed in 06a56e063c327b0606f9e9690764279d424646b2.

@bb-migration

This comment has been minimized.

bb-migration commented Apr 7, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Awesome. Thanks for checking my (horrible) work.

@bb-migration

This comment has been minimized.

bb-migration commented Sep 1, 2015

Original comment by marcio_ (Bitbucket: marcio_, GitHub: Unknown):


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 "setup.py", line 133, in <module>
    'Topic :: Software Development :: Libraries :: Python Modules',
  File "C:\Python26\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python26\lib\distutils\dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "C:\Python26\lib\distutils\dist.py", line 995, in run_command
    cmd_obj.run()
  File "build\bdist.win32\egg\setuptools\command\test.py", line 142, in run
  File "build\bdist.win32\egg\setuptools\command\test.py", line 122, in with_project_on_sys_path
  File "build\bdist.win32\egg\setuptools\command\test.py", line 163, in run_tests
  File "C:\Python26\lib\unittest.py", line 817, in __init__
    self.runTests()
  File "C:\Python26\lib\unittest.py", line 861, in runTests
    result = testRunner.run(self.test)
AttributeError: 'NoneType' object has no attribute 'run'
@bb-migration

This comment has been minimized.

bb-migration commented Sep 3, 2015

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


@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 setup.py 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?

@bb-migration

This comment has been minimized.

bb-migration commented Sep 3, 2015

Original comment by marcio_ (Bitbucket: marcio_, GitHub: Unknown):


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.

jaraco added a commit that referenced this issue Mar 29, 2016

Merged in koterpillar/setuptools (pull request #183)
Remove CVS and Subversion references in include_package_data docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment