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

DistutilsGetoptError: invalid long option 'exclude-dir=': must be a string of length >= 2 #4

Open
mat128 opened this issue Aug 20, 2015 · 7 comments

Comments

@mat128
Copy link
Contributor

mat128 commented Aug 20, 2015

When invoking through setup.py nosetests (instead of nosetests directly), the following error message is provided, even if no exclude dirs are specified.

py27 runtests: commands[0] | python setup.py nosetests
Traceback (most recent call last):
File "setup.py", line 3, in
setup()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 138, in setup
ok = dist.parse_command_line()
File "/Users/mmitchell/projects/nose-exclude-demo/.tox/py27/lib/python2.7/site-packages/setuptools/dist.py", line 271, in parse_command_line
result = _Distribution.parse_command_line(self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 467, in parse_command_line
args = self._parse_command_opts(parser, args)
File "/Users/mmitchell/projects/nose-exclude-demo/.tox/py27/lib/python2.7/site-packages/setuptools/dist.py", line 555, in _parse_command_opts
nargs = _Distribution._parse_command_opts(self, parser, args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 564, in _parse_command_opts
(args, opts) = parser.getopt(args[1:])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/fancy_getopt.py", line 253, in getopt
self._grok_option_table()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/fancy_getopt.py", line 171, in _grok_option_table
"must be a string of length >= 2") % long
distutils.errors.DistutilsGetoptError: invalid long option 'exclude-dir=': must be a string of length >= 2
ERROR: InvocationError: '/Users/mmitchell/projects/nose-exclude-demo/.tox/py27/bin/python setup.py nosetests'

I setup a demo repository to reproduce the issue (simply run tox -r):
https://github.com/mat128/nose-exclude-demo

And a travis-ci job to demonstrate it:
https://travis-ci.org/mat128/nose-exclude-demo

This happens only after 0.4.0 was released.
Thank you

@kgrandis
Copy link
Owner

Interesting. It looks like something related to the way I approached py3ification, unicode, and getopt. I'll need to investigate further.

That being said, I don't believe python setup.py nosetests ever worked error free since I include one always failing test that is only excluded through setup.py test using Nose's PluginTester.

@mat128
Copy link
Contributor Author

mat128 commented Aug 20, 2015

Worked great for us prior to last release. Maybe I can bring up a test case that installs 0.3.0... Let me check.

@mat128
Copy link
Contributor Author

mat128 commented Aug 20, 2015

Yup, worked on 0.3.0: https://travis-ci.org/mat128/nose-exclude-demo/builds/76495668
Let me know if there is anything else I can provide.

@kgrandis
Copy link
Owner

I don't know too much about the Travis environment (or maybe tox?), but it doesn't look like those builds are actually running any tests at all, whereas if I run the command from a shell (py27 @ 0.3.0) I get:

$ python setup.py nosetests
running nosetests
running egg_info
writing requirements to nose_exclude.egg-info/requires.txt
writing nose_exclude.egg-info/PKG-INFO
writing top-level names to nose_exclude.egg-info/top_level.txt
writing dependency_links to nose_exclude.egg-info/dependency_links.txt
writing entry points to nose_exclude.egg-info/entry_points.txt
reading manifest file 'nose_exclude.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'nose_exclude.egg-info/SOURCES.txt'
...F......nose.plugins.nose_exclude: WARNING: The following path was not found: --exclude-dir=test_dirs/test_i_dont_exist
............
======================================================================
FAIL: test.test_i_should_never_run
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kurt/.virtualenvs/noseexclude/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Users/kurt/sandbox/nose-exclude-git/test_dirs/test_not_me/test.py", line 3, in test_i_should_never_run
    assert False
AssertionError

----------------------------------------------------------------------
Ran 22 tests in 0.432s

FAILED (failures=1)

https://travis-ci.org/kgrandis/nose-exclude/jobs/76376881 (@0.4.0) shows tests being run.
So, I do think even if I resolve this particular getopt issue once you tweak your configure to run the tests it'll still break.

@kgrandis
Copy link
Owner

I think if you wanted to use nosetests.py proper, you would need something like
nosetests.py tests.py to keep nose from running down into the tests subdir that contain known failures or use something like nose-exclude :p

@mat128
Copy link
Contributor Author

mat128 commented Aug 21, 2015

In the travis test results, you dont see any test being run because I purposefully built the smallest possible test, providing only a virtualenv, nose and nose-exclude. Simply running this through setup.py nosetests (without specifying any exclude-dir) resulted in a crash.

I did more research and found new stuff:

  • Removing "from future import unicode_literals" fixes the issue (but I guess you want unicode?)
  • Wrapping all add_option first parameters in str() fixes the issue (I'll push a PR for this)
  • The issue lies within fancy_getopts: I found this bug from 2013 https://bugs.python.org/issue18936 and fancy_getopts code which is spot on:
    # Type- and value-check the option names
    if not isinstance(long, str) or len(long) < 2:
    raise DistutilsGetoptError(("invalid long option '%s': "
    "must be a string of length >= 2") % long)

@kgrandis
Copy link
Owner

excellent. thanks for the legwork. I'll review and try to get this released this weekend.

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

No branches or pull requests

2 participants