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

Python 3.10.0a1: FAIL: sure.that_with_context() when no context is given it fails #169

Open
1 task done
hroncok opened this issue Oct 20, 2020 · 1 comment
Open
1 task done

Comments

@hroncok
Copy link
Contributor

hroncok commented Oct 20, 2020

Issue Type

Please specify the type of the issue you want to submit:

  • Bug Report

Versions & Configuration

Please specify the following things:

  • version of sure: 95f2044
  • implementation and version of python: CPython 3.10.0a1
  • operating system: Linux (Fedora, x86_64)

Steps to reproduce (Expected and Actual Results)

Please specify the steps to reproduce your issue including the expected and the actual results.

$ tox -e py310
GLOB sdist-make: .../sure/setup.py
py310 inst-nodeps: .../sure/.tox/.tmp/package/1/sure-1.4.11.zip
py310 installed: colorama==0.4.4,coverage==5.3,mock==4.0.2,nose==1.3.7,rednose==1.3.0,six==1.15.0,sure @ file://.../sure/.tox/.tmp/package/1/sure-1.4.11.zip,termstyle==0.1.11
py310 run-test-pre: PYTHONHASHSEED='1043129750'
py310 run-test: commands[0] | nosetests --rednose -vv --with-coverage --cover-package=sure
nose.config: INFO: Ignoring files matching ['^\\.', '^_', '^setup\\.py$']
nose.plugins.cover: INFO: Coverage report will include only packages: ['sure']
issues.test_issue_104.test_issue_104 ... passed
Correctly handle {} characters in matcher string ... passed
Test for unicode error when comparing bytes ... passed
Test for GitHub Issue #139 ... passed
issues.test_issue_148.test_should_compare_dict_with_non_orderable_key_types ... passed
issues.test_issue_148.test_should_compare_dict_with_enum_keys ... passed
Allow monkey-patching of methods already implemented by sure. ... passed
issues.test_issue_48.test_issue_48 ... passed
this, it, these and those are all synonyms ... passed
this(4).should.equal(2 + 2) ... passed
this(1).should.be.within(0, 2) ... passed
this(True).should.be.ok ... passed
this(False).should.be.false ... passed
this(None).should.be.none ... passed
this(None).should.be.none ... passed
this(function).should.be.callable ... passed
this(iterable).should.be.empty ... passed
this(iterable).should.have.length_of(N) ... passed
this(X).should.be.greater_than(Y) ... passed
this(X).should.be.greater_than_or_equal_to(Y) ... passed
this(X).should.be.lower_than(Y) ... passed
this(X).should.be.lower_than_or_equal_to(Y) ... passed
this(X).should.be(X) when X is a reference to the same object ... passed
this(instance).should.have.property(property_name) ... passed
this(instance).should.have.property(property_name).being or .with_value should allow chain up ... passed
this(dictionary).should.have.key(key_name) ... passed
this(dictionary).should.have.key(key_name).being or .with_value should allow chain up ... passed
this('   aa ... passed
test usage of repr() inside expect(complex1).to.equal(complex2) ... passed
test usage of repr() inside expect(complex1).to.equal(complex2) ... passed
expect('some string').to.match(r'\w{4} \w{6}') matches regex ... passed
expect('some string').to.contain('tri') ... passed
test_assertion_builder.test_catching_exceptions ... passed
test_assertion_builder.test_catching_exceptions_with_params ... passed
test_assertion_builder.test_success_with_params ... passed
test_assertion_builder.test_success_with_params_exception ... passed
test_assertion_builder.test_throw_matching_regex ... passed
'something'.should_not.be.different('SOMETHING'.lower()) ... passed
.equal() Should convert mock._CallList instances to lists ... passed
.equal(what, epsilon=XXX) should check for equality with an epsilon for float values ... passed
.equal() with dict containing tuples as keys should work ... passed
.equal(OrderedDict) should check if two ordered dicts are the same ... passed
test_assertion_builder.test_equals_anything ... passed
test_assertion_builder.test_equals_crosstype ... passed
anything that inherits from object should be patched ... passed
do not patch already existing class attributes with same name ... passed
do not patch already existing instance attributes with same name ... passed
dir(obj) should conceal names of methods that were grafted by sure ... passed
test extending sure with a custom assertion. ... passed
test extending sure with a custom chain method. ... passed
test extending sure with a custom chain property. ... passed
Test ensure simple assertion ... passed
Test that ensure only captures AssertionErrors ... passed
sure.with_context() runs setup before the function itself ... passed
sure.that_with_context() when no context is given it fails ... FAILED
sure.that_with_context() in a failing test ... passed
sure.with_context() runs teardown before the function itself ... passed
that() is_a(object) ... passed
that() equals(string) ... passed
that() differs(object) ... passed
that() has(object) ... passed
that().at(object).equals(object) ... passed
that() len_is(number) ... passed
that() len_greater_than(number) ... passed
that() len_greater_than(number) raise AssertionError ... passed
that() len_greater_than_or_equals(number) ... passed
that() len_greater_than_or_equals(number) raise AssertionError ... passed
that() len_lower_than(number) ... passed
that() len_lower_than(number) raise AssertionError ... passed
that() len_lower_than_or_equals(number) ... passed
that() len_lower_than_or_equals(number) raise AssertionError ... passed
that(iterable).the_attribute('name').equals('value') ... passed
that(iterable, within_range=(1, 2)).the_attribute('name').equals('value') ... passed
that(iterable).every_one_is('value') ... passed
that(iterable).in_each('').equals('value') ... passed
that(callable, with_args=[arg1], and_kwargs={'arg2': 'value'}).raises(SomeException) ... passed
that('String\n with BREAKLINE').looks_like('string with breakline') ... passed
that(callable(RuntimeError)).raises(TypeError) ... passed
that(callable, with_args=['foo']).raises(FooError) ... passed
that(callable).doesnt_raise(FooError) and does_not_raise ... passed
that('foobar').contains('foo') ... passed
that('foobar').does_not_contain('123'), .doesnt_contain ... passed
that('foobar').contains(None) ... passed
that(None).contains('bungalow') ... passed
that(some_iterable).is_empty and that(something).are_empty ... passed
that(something_not_iterable).is_empty and that(something_not_iterable).are_empty raises ... passed
that(something_iterable).matches(another_iterable) ... passed
within(five=miliseconds) will pass ... passed
within(five=miliseconds) will fail ... passed
test_old_api.test_word_to_number ... passed
test_old_api.test_word_to_number_fail ... passed
testing microseconds convertion ... passed
testing miliseconds convertion ... passed
testing seconds convertion ... passed
testing minutes convertion ... passed
within(five=miliseconds) gives utc parameter ... passed
that.is_a_matcher should absorb callables to be used as matcher ... passed
sure.with_context() accepts a list of callbacks for setup ... passed
sure.with_context() runs teardown before the function itself ... passed
@scenario aliases @that_with_context for setup and teardown ... passed
the actions always returns the context ... passed
the actions should be able to declare the variables they provide ... passed
it fails when an action doesn't fulfill its agreements ... passed
it fails when an action depends on some attribute that is not provided by any other previous action ... passed
it fails when an action depends on some attribute that is being provided by other actions ... passed
that(dict(name='foobar')).contains('name') ... passed
that(['foobar', '123']).contains('foobar') ... passed
that(set(['foobar', '123']).contains('foobar') ... passed
that(('foobar', '123')).contains('foobar') ... passed
VariablesBag() provides a meaningful error when attr does not exist ... passed
the actions should be able to declare the variables they provide ... passed
that() deep_equals(dict) succeeding on level 1 ... passed
that() deep_equals(dict) failing on level 1 ... passed
that(list) deep_equals(list) succeeding on level 1 ... passed
that(list) deep_equals(list) failing on level 1 ... passed
that(list) deep_equals(list) failing by length (len(X) > len(Y)) ... passed
that(list) deep_equals(list) failing by length (len(Y) > len(X)) ... passed
that(X) deep_equals(Y) fails when Y is missing a key that X has ... passed
that(X) deep_equals(Y) fails with basic vc complex type ... passed
that(X) deep_equals(Y) fails with complex vc basic type ... passed
that(tuple) deep_equals(tuple) succeeding on level 1 ... passed
that(tuple) deep_equals(tuple) failing on level 1 ... passed
that(tuple) deep_equals(tuple) failing by length (len(X) > len(Y)) ... passed
that(tuple) deep_equals(tuple) failing by length (len(Y) > len(X)) ... passed
that() deep_equals(dict) falling back to generic comparator ... passed
that() deep_equals(dict) with generic comparator failing ... passed
that() deep_equals(dict) with generic comparator failing ... passed
that() deep_equals(dict) succeeding on level 2 ... passed
that() deep_equals(dict) succeeding on level 2 ... passed
that() deep_equals(dict) failing on level 2 ... passed
that() deep_equals(dict) failing on level 3 ... passed
that() deep_equals(dict) failing on level 3 when missing a key ... passed
that() deep_equals(dict) failing on level 3 when has an extra key ... passed
that() deep_equals(dict) failing on level 3 when has an extra key ... passed
that(list) deep_equals(list) failing by length (len(X) > len(Y)) ... passed
that(list) deep_equals(list) failing by length (len(Y) > len(X)) ... passed
@sure.work_in_progress should set an internal flag into `sure` ... passed
that() equals(string) when it's supposed to fail ... passed
that(callable).raises('message') should compare the message ... passed
test_old_api.test_deep_equals_weird ... passed
safe_repr should display a simple list ... passed
safe_repr should return a sorted repr ... passed
dicts nested inside values should also get sorted ... passed
dicts with unicode should work properly ... passed
======================================================================
1) FAIL: sure.that_with_context() when no context is given it fails
----------------------------------------------------------------------
   Traceback (most recent call last):
    .tox/py310/lib/python3.10/site-packages/nose/case.py line 198 in runTest
      self.test(*self.arg)
    tests/test_old_api.py line 59 in test_context_is_not_optional
      assert that(it_crashes).raises(
    sure/old.py line 145 in raises
      raise AssertionError('''
   AssertionError: <function test_context_is_not_optional.<locals>.it_crashes at 0x7f9f400271f0> raised TypeError, but the exception message does not
                       match.
   
   EXPECTED:
   the function it_crashes defined at test_old_api.py line 56, is being decorated by either @that_with_context or @scenario, so it should take at least 1 parameter, which is the test context
   
   GOT:
   test_context_is_not_optional.<locals>.it_crashes() takes 0 positional arguments but 1 was given

Name                 Stmts   Miss  Cover   Missing
--------------------------------------------------
sure/__init__.py       618     52    92%   96-97, 126, 187-200, 209, 395, 464-473, 500, 522, 631-636, 703, 712-713, 716, 800-807, 811-817, 847-855, 864-865, 1043, 1078-1079, 1082
sure/compat.py          71     22    69%   10-11, 17-37, 60, 66-67, 102-104
sure/core.py           161      6    96%   152, 162, 220, 259, 265-266
sure/deprecated.py       4      0   100%
sure/magic.py           22      2    91%   51, 64
sure/old.py            263     21    92%   33-34, 62, 93, 123, 157-163, 170-184, 214, 238, 392-393, 399
sure/registry.py         2      0   100%
sure/terminal.py        29      8    72%   29, 34, 42, 48, 54, 58-60
--------------------------------------------------
TOTAL                 1170    111    91%
-----------------------------------------------------------------------------
144 tests run in 0.835 seconds. 
1 FAILED (143 tests passed)
ERROR: InvocationError for command .../sure/.tox/py310/bin/nosetests --rednose -vv --with-coverage --cover-package=sure (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   py310: commands failed

Context

In Fedora, we try to bootstrap our Python packages with early development Python versions soon to uncover errors in libraries as well as Python itself. With sure, I was unable to recognize what's wrong. You can install Python 3.10 on Fedora with sudo dnf --enablerepo=updates-testing install python3.10.

@yan12125
Copy link

yan12125 commented Dec 7, 2021

Here is a fix for the test failure:

diff --git a/sure/__init__.py b/sure/__init__.py
index ef50bd4..d4c2afb 100644
--- a/sure/__init__.py
+++ b/sure/__init__.py
@@ -126,7 +126,7 @@ class CallBack(object):
             err = traceback.format_exc().splitlines()[-1]
             err = err.replace("{0}:".format(exc_klass.__name__), "").strip()
 
-            if err.startswith(self.callback_name) and (
+            if self.callback_name in err and (
                 "takes no arguments (1 given)" in err
                 or "takes 0 positional arguments but 1 was given" in err
             ):

The reason is that Python 3.10 changes some error messages to use qualified function names (python/cpython#20236), so detecting it fails.

archlinux-github pushed a commit to archlinux/svntogit-community that referenced this issue Dec 7, 2021
See: gabrielfalcao/sure#169



git-svn-id: file:///srv/repos/svn-community/svn@1065520 9fca08f4-af9d-4005-b8df-a31f2cc04f65
archlinux-github pushed a commit to archlinux/svntogit-community that referenced this issue Dec 7, 2021
See: gabrielfalcao/sure#169

git-svn-id: file:///srv/repos/svn-community/svn@1065520 9fca08f4-af9d-4005-b8df-a31f2cc04f65
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