test fails with py3.8 and pytest
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.
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?
Yep, makes sense :) I'll prepare a PR by the end of the day with all the fixes :+1:
That's awesome! Thank you so much <o/ I'll take a look at the PR for sure!