benjaminp / six

Python 2 and 3 compatibility library
https://six.readthedocs.io/
MIT License
989 stars 274 forks source link

Multitple testfailures with 1.10.0 #139

Open benjaminp opened 9 years ago

benjaminp commented 9 years ago

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


#!python

=============================================== FAILURES ================================================
_________________________________________ test_assertCountEqual _________________________________________

    @py.test.mark.skipif("sys.version_info[:2] < (2, 7) or sys.version_info[:2] in ((3, 0), (3, 1))")
    def test_assertCountEqual():
        class TestAssertCountEqual(unittest.TestCase):
            def test(self):
                with self.assertRaises(AssertionError):
                    six.assertCountEqual(self, (1, 2), [3, 4, 5])

                six.assertCountEqual(self, (1, 2), [2, 1])

>       TestAssertCountEqual('test').test()

test_six.py:825:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test_six.py:821: in test
    six.assertCountEqual(self, (1, 2), [3, 4, 5])
six.py:667: in assertCountEqual
    return getattr(self, _assertCountEqual)(*args, **kwargs)
/usr/lib64/python3.3/unittest/case.py:999: in assertCountEqual
    self.fail(msg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <test_six.TestAssertCountEqual testMethod=test>
msg = 'Element counts were not equal:\nFirst has 1, Second has 0:  1\nFirst has 1, Second has 0:  2\nFirst has 0, Second has 1:  3\nFirst has 0, Second has 1:  4\nFirst has 0, Second has 1:  5'

    def fail(self, msg=None):
        """Fail immediately, with the given message."""
>       raise self.failureException(msg)
E       AssertionError: Element counts were not equal:
E       First has 1, Second has 0:  1
E       First has 1, Second has 0:  2
E       First has 0, Second has 1:  3
E       First has 0, Second has 1:  4
E       First has 0, Second has 1:  5

/usr/lib64/python3.3/unittest/case.py:508: AssertionError
___________________________________________ test_assertRegex ____________________________________________

    @py.test.mark.skipif("sys.version_info[:2] < (2, 7)")
    def test_assertRegex():
        class TestAssertRegex(unittest.TestCase):
            def test(self):
                with self.assertRaises(AssertionError):
                    six.assertRegex(self, 'test', r'^a')

                six.assertRegex(self, 'test', r'^t')

>       TestAssertRegex('test').test()

test_six.py:837:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test_six.py:833: in test
    six.assertRegex(self, 'test', r'^a')
six.py:675: in assertRegex
    return getattr(self, _assertRegex)(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <test_six.TestAssertRegex testMethod=test>, text = 'test'
expected_regex = <_sre.SRE_Pattern object at 0x7f9752fa7618>
msg = "Regex didn't match: '^a' not found in 'test'"

    def assertRegex(self, text, expected_regex, msg=None):
        """Fail the test unless the text matches the regular expression."""
        if isinstance(expected_regex, (str, bytes)):
            assert expected_regex, "expected_regex must not be empty."
            expected_regex = re.compile(expected_regex)
        if not expected_regex.search(text):
            msg = msg or "Regex didn't match"
            msg = '%s: %r not found in %r' % (msg, expected_regex.pattern, text)
>           raise self.failureException(msg)
E           AssertionError: Regex didn't match: '^a' not found in 'test'

/usr/lib64/python3.3/unittest/case.py:1119: AssertionError
________________________________________ test_assertRaisesRegex _________________________________________

    @py.test.mark.skipif("sys.version_info[:2] < (2, 7)")
    def test_assertRaisesRegex():
        class TestAssertRaisesRegex(unittest.TestCase):
            def test(self):
                with six.assertRaisesRegex(self, AssertionError, '^Foo'):
                    raise AssertionError('Foo')

                with self.assertRaises(AssertionError):
                    with six.assertRaisesRegex(self, AssertionError, r'^Foo'):
                        raise AssertionError('Bar')

>       TestAssertRaisesRegex('test').test()

test_six.py:851:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test_six.py:849: in test
    raise AssertionError('Bar')
/usr/lib64/python3.3/unittest/case.py:167: in __exit__
    expected_regex.pattern, str(exc_value)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <unittest.case._AssertRaisesContext object at 0x7f9750d3fc10>
standardMsg = '"^Foo" does not match "Bar"'

    def _raiseFailure(self, standardMsg):
        msg = self.test_case._formatMessage(self.msg, standardMsg)
>       raise self.test_case.failureException(msg)
E       AssertionError: "^Foo" does not match "Bar"

/usr/lib64/python3.3/unittest/case.py:123: AssertionError
============================ 3 failed, 182 passed, 1 skipped in 0.75 seconds ============================

mdw-at-linuxbox commented 7 years ago

I ran into this problem on a fedora 25 machine with python 2.7.13 and many packages. After a fair bit of experimentation, I managed to boil it down to the following minimal setup that reproduces the same behavior.

cat <<'.'>/tmp/r appdirs==1.4.3 betamax==0.8.0 certifi==2017.4.17 chardet==3.0.3 idna==2.5 packaging==16.8 pika==0.10.0 py==1.4.33 pyparsing==2.2.0 PySocks==1.6.7 pytest==2.9.2 requests==2.16.5 six==1.10.0 urllib3==1.21.1 . virtualenv /tmp/f3 . /tmp/f3/bin/activate pip install -r /tmp/r

** at this point, the virtualenv will produce the problem if pointed at a copy of six that's been built: py.test test_six.py

The virtualenv can then be "fixed" by running one of these 2: pip install -U pytest (pytest 3.1.0 works.)

So I'm not quite sure how I would describe this problem. Bugs arising from complex interaction of non-minimal set of out of date python components?