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

parses long options with no equals sign incorrectly #7

Closed
akaihola opened this issue Jan 26, 2010 · 13 comments
Closed

parses long options with no equals sign incorrectly #7

akaihola opened this issue Jan 26, 2010 · 13 comments
Labels
Milestone

Comments

@akaihola
Copy link
Contributor

Python's optparse accepts long options also without the equals sign (e.g. --verbose 2). Django-nose fails to strip out the values of such Django options when creating the nose command line:

$ ./manage.py test --verbosity 0
======================================================================
ERROR: Failure: OSError (No such file /home/akaihola/testproject/0)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/nose/failure.py", line 39, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/akaihola/testproject/0

----------------------------------------------------------------------
Ran 20 tests in 2.844s

FAILED (errors=1)

To solve this "correctly", some serious hacking with optparse is probably needed. Or, known Django options with arguments could be handled specially.

Or maybe it would be possible to "merge" Django's and nose's option parsers?

@slinkp
Copy link

slinkp commented Mar 14, 2011

This affects an awful lot of useful arguments: --with-profile, --nologcapture, --coverage, --with-id, --failed, --with-xunit, etc etc.

@slinkp
Copy link

slinkp commented Apr 1, 2011

It's not just long options. Value-less short options like -s are treaded as module names to test:

$ django-admin.py test ebpub.db -- -s
............................................E
======================================================================
ERROR: Failure: OSError (No such file /home/pw/builds/openblock/builds/20110106/src/openblock/-s)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/nose/failure.py", line 39, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/pw/builds/openblock/builds/20110106/src/openblock/-s

@jbalogh
Copy link
Contributor

jbalogh commented Apr 15, 2011

@slinkp What version of django-nose do you have? Your example works for me on master.

@slinkp
Copy link

slinkp commented Apr 15, 2011

I have django-nose 1.2. I see there's now a 1.3 on pypi, will try that.

@slinkp
Copy link

slinkp commented Apr 15, 2011

1.3 still has the same problem, and I just tried with django-nose master as of 1d8cb63. Same problem.
FYI, I have nose 0.11.1 and python 2.6.5.

@jbalogh
Copy link
Contributor

jbalogh commented Apr 15, 2011

Ah, I have 2.7. Perhaps something changed in optparse in between.

@obeattie
Copy link

I am seeing the same issue: Python 2.7.1, Nose 1.0.0, django-nose 0.1.3

Very strange indeed.

@camilonova
Copy link
Member

I can replicate the issue as well and is a problem with the option parser, I'm on it.

@jwhitlock
Copy link
Contributor

It's been a few years, but this is still broken for me. @camilonova, any interest in submitting a PR against current master?

@jwhitlock jwhitlock added needinfo and removed easy labels Jul 3, 2015
@jwhitlock jwhitlock added this to the v1.4.2 milestone Jul 3, 2015
@camilonova
Copy link
Member

@jwhitlock Sorry pal, It's been a while, someone else should take care of it.

@jwhitlock
Copy link
Contributor

@camilonova no problem - thanks for the original code, it's a good start.

@jwhitlock jwhitlock removed the needinfo label Jul 5, 2015
@jwhitlock jwhitlock modified the milestones: v1.4.3, v1.4.2 Oct 7, 2015
@jwhitlock
Copy link
Contributor

I left this comment on issue 142, but this might be a better place, so duplicating.

I started to dive into this, and the fix will be longer than expected, so bumping to v1.4.3.

Short version: using --option value probably won't work (yet), but --option=value might.

Longer version:

Command line parsing is complicated:

  1. django-nose merges nose parse options with Django parse options. There is a different strategy for Django 1.6 and earlier (using optparse) from Django 1.7 and later (using argparse).
  2. Django's management command framework parses the command line
  3. Django's test command class interprets some, but not all, of the command line options
  4. django-nose reformats the command-line arguments to modify Django-specific options
  5. nose's command line parser re-parses the reformatted command-line arguments

The problem is that Django likes --option value (and this is what ./manage.py test --help will show), but nose likes --option=value. We're already manipulating the command-line args in step 4, to make things like verbosity work, but something more generic is needed for other options with values. Ideally, we could pass the results of Django's command line parsing to nose and skip the re-parsing steps (4 and 5), but I'm not sure if nose has the right hooks, and it may cause other issues.

jwhitlock added a commit that referenced this issue Dec 2, 2015
When a long option is used without an equals sign (such as --processes 2
or --verbosity 2), an equals sign is added (--processes=2,
--verbosity=2) before passing to nose.  This only works in Django 1.8 or
later. For Django 1.7 and earlier, --verbosity is handled, but the
caller must use --option=value for other parameters.

Fixes #7
jwhitlock added a commit that referenced this issue Dec 2, 2015
When a long option is used without an equals sign (such as --processes 2
or --verbosity 2), the argument is passed to nose.  This only works in
Django 1.8 or later. For Django 1.7 and earlier, --verbosity is handled,
but the caller must use --option=value for other parameters.

Fixes #7
jwhitlock added a commit that referenced this issue Dec 2, 2015
When a long option is used without an equals sign (such as --processes 2
or --verbosity 2), the argument is passed to nose.  This only works in
Django 1.8 or later. For Django 1.7 and earlier, --verbosity is handled,
but the caller must use --option=value for other parameters.

Fixes #7
jwhitlock added a commit that referenced this issue Dec 2, 2015
For Django 1.7 and earlier, hard-code the list of options that include a
parameter.

Fixes #7
jwhitlock added a commit that referenced this issue Dec 28, 2015
For Django 1.7 and earlier, hard-code the list of options that include a
parameter.

Fixes #7
@jagguli
Copy link

jagguli commented Mar 29, 2016

I had this same error, somehow removing .noseids fixed it

- TRACEBACK --------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 329, in run
    testMethod()
  File "/usr/lib/python2.7/site-packages/nose/failure.py", line 42, in runTest
    raise self.exc_class(self.exc_val)
OSError: No such file /home/steven/test/testproj/3
--------------------------------------------------------------------------------

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

No branches or pull requests

7 participants