Skip to content

AttributeError: 'MyOptionParser' object has no attribute 'parse_known_args' #362

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

Closed
pytestbot opened this issue Oct 1, 2013 · 6 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Damien Nozay (BitBucket: dnozay, GitHub: dnozay)


IMHO this is a regression

python 2.6.1 + pytest < 2.4.0 works

python 2.6.1 + pytest 2.4.0 =

#!python


Generating XML reports...
Traceback (most recent call last):
  File "/home/damien/test-venv/bin/py.test", line 8, in <module>
    load_entry_point('pytest==2.4.0', 'console_scripts', 'py.test')()
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/config.py", line 18, in main
    config = _prepareconfig(args, plugins)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/config.py", line 63, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/core.py", line 364, in __call__
    return self._docall(methods, kwargs)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/core.py", line 375, in _docall
    res = mc.execute()
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/core.py", line 293, in execute
    res = method(**kwargs)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/helpconfig.py", line 25, in pytest_cmdline_parse
    config = __multicall__.execute()
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/core.py", line 293, in execute
    res = method(**kwargs)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/config.py", line 618, in pytest_cmdline_parse
    self.parse(args)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/config.py", line 711, in parse
    self._preparse(args)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/config.py", line 691, in _preparse
    args=args, parser=self._parser)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/core.py", line 364, in __call__
    return self._docall(methods, kwargs)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/core.py", line 375, in _docall
    res = mc.execute()
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/core.py", line 293, in execute
    res = method(**kwargs)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/capture.py", line 17, in pytest_load_initial_conftests
    ns = parser.parse_known_args(args)
  File "/home/damien/test-venv/lib/python2.6/site-packages/_pytest/config.py", line 175, in parse_known_args
    return optparser.parse_known_args(args)[0]
AttributeError: 'MyOptionParser' object has no attribute 'parse_known_args'

@pytestbot
Copy link
Contributor Author

Original comment by Damien Nozay (BitBucket: dnozay, GitHub: dnozay):


parse_known_args is available with argparse which is not present by default with python 2.6.1; which itself ships with optparse.

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


Not sure how you get this problem. pytest should pull in argparse as a package when installing. (version 1.2.1). Does it not in your python2.6 environment? With my python2.6.8 and installing pytest i don't get this problem.

@pytestbot
Copy link
Contributor Author

Original comment by Damien Nozay (BitBucket: dnozay, GitHub: dnozay):


here is my test:

#!bash

#!/bin/bash
set +e
set +x

/opt/python-2.6.1/bin/virtualenv test-env
source test-env/bin/activate
pip install unittest-xml-reporting
pip install unittest2
pip install nose
pip install argparse
pip install "pytest == 2.4.0"


python --version

cat > tests.py << EOF
import random
try:
    import unittest2 as unittest
except ImportError:
    import unittest
import xmlrunner
import argparse

class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.seq = list(range(10))

    @unittest.skip("demonstrating skipping")
    def test_skipped(self):
        self.fail("shouldn't happen")

    def test_shuffle(self):
        # make sure the shuffled sequence does not lose any elements
        random.shuffle(self.seq)
        self.seq.sort()
        self.assertEqual(self.seq, list(range(10)))

        # should raise an exception for an immutable sequence
        self.assertRaises(TypeError, random.shuffle, (1,2,3))

    def test_choice(self):
        element = random.choice(self.seq)
        self.assertTrue(element in self.seq)

    def test_sample(self):
        with self.assertRaises(ValueError):
            random.sample(self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assertTrue(element in self.seq)

if __name__ == '__main__':
    unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))


EOF

python tests.py
py.test  --junitxml=results.xml
nosetests --with-xunit




set


@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


i don't get an AttributeError but a ValueError. The latter should be fixed, though, on trunk. You can install it via::

pip install -i http://devpi.net/hpk/dev/+simple/ -U pytest

(should give you pytest-2.4.1.dev1). Chances are you still get an AttributeError. Please let me know.

@pytestbot
Copy link
Contributor Author

Original comment by Damien Nozay (BitBucket: dnozay, GitHub: dnozay):


#!bash

Generating XML reports...
============================= test session starts ==============================
platform linux2 -- Python 2.6.1 -- pytest-2.4.1.dev1
collected 4 items

tests.py ...s

 generated xml file: /home/damien/results.xml 
===================== 3 passed, 1 skipped in 0.08 seconds ======================

this seems to work.
thank you.

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


resolved with pytest-2.4.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant