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

test fails with py3.8 and pytest #46

Open
paolostivanin opened this issue Apr 14, 2020 · 3 comments · May be fixed by #47
Open

test fails with py3.8 and pytest #46

paolostivanin opened this issue Apr 14, 2020 · 3 comments · May be fixed by #47

Comments

@paolostivanin
Copy link

paolostivanin commented Apr 14, 2020

As nose won't be supported with python 3.9 and up, I was trying to port the tests to pytest.
All tests but 1 passed. In particular, I faced an issue with test_dir_without_args_returns_names_in_local_scope:

[    3s] =================================== FAILURES ===================================
[    3s] ______________ test_dir_without_args_returns_names_in_local_scope ______________
[    3s] 
[    3s]     def test_dir_without_args_returns_names_in_local_scope():
[    3s]         """dir() without arguments should return the names from the local scope
[    3s]         of the calling frame, taking into account any indirection added
[    3s]         by __filtered_dir__
[    3s]         """
[    3s]     
[    3s]         # Given that I have a local scope with some names bound to values
[    3s]         z = 1
[    3s]         some_name = 42
[    3s]     
[    3s]         # Then I see that `dir()` correctly returns a sorted list of those names
[    3s]         assert 'some_name' in dir()
[    3s] >       assert dir() == sorted(locals().keys())
[    3s] E       AssertionError: assert ['@py_assert0...me_name', 'z'] == ['@py_assert0...me_name', 'z']
[    3s] E         At index 1 diff: '@py_assert2' != '@py_assert1'
[    3s] E         Right contains one more item: 'z'
[    3s] E         Full diff:
[    3s] E         - ['@py_assert0', '@py_assert2', '@py_assert4', 'some_name', 'z']
[    3s] E         + ['@py_assert0', '@py_assert1', '@py_assert2', '@py_assert4', 'some_name', 'z']
[    3s] E         ?                 +++++++++++++++
[    3s] 
[    3s] tests/unit/test_forbidden_fruit.py:172: AssertionError
[    3s] ========================= 1 failed, 16 passed in 0.06s =========================

I'm using python 3.8 and pytest on openSUSE.

@clarete
Copy link
Owner

clarete commented Apr 14, 2020

Hi @paolostivanin! Thanks for working on the porting! pytest will be the way to go for sure!

On this specific test, I am not really sure why locals() & dir() are diverging, but it looks like it's something pytest itself is doing (we're not the only ones to fiddle with the inner workings of dir, I guess :D).

I'm not really really sure if that test is really useful the way it is either way. I'd just change it so we don't look at things that aren't exactly relevant for the library. In other words, maybe instead of

assert dir() == sorted(locals().keys())

we could go just for repeating what we did in the previous line

assert 'a' in dir()

What do you think?

@paolostivanin
Copy link
Author

Yep, makes sense :)
I'll prepare a PR by the end of the day with all the fixes 👍

@paolostivanin paolostivanin linked a pull request Apr 15, 2020 that will close this issue
@clarete
Copy link
Owner

clarete commented Apr 16, 2020

That's awesome! Thank you so much <o/
I'll take a look at the PR for sure!

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

Successfully merging a pull request may close this issue.

2 participants