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

0.8.3: pytest is failing #34

Closed
kloczek opened this issue Apr 6, 2022 · 5 comments
Closed

0.8.3: pytest is failing #34

kloczek opened this issue Apr 6, 2022 · 5 comments

Comments

@kloczek
Copy link

kloczek commented Apr 6, 2022

I'm trying to package your module as an rpm package. So I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I'm calling build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix>
  • run pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-executing-0.8.3-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-executing-0.8.3-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/executing-0.8.3
collected 2 items / 1 error

================================================================================== ERRORS ==================================================================================
___________________________________________________________________ ERROR collecting tests/test_main.py ____________________________________________________________________
executing/executing.py:317: in executing
    args = executing_cache[key]
E   KeyError: (<code object <module> at 0x7f98855a0ea0, file "/home/tkloczko/rpmbuild/BUILD/executing-0.8.3/tests/test_main.py", line 2>, 140293049028256, 418)

During handling of the above exception, another exception occurred:
executing/executing.py:346: in find
    node_finder = NodeFinder(frame, stmts, tree, lasti)
executing/executing.py:636: in __init__
    matching = list(self.matching_nodes(exprs))
executing/executing.py:702: in matching_nodes
    original_index = only(
executing/executing.py:164: in only
    raise NotOneValueFound('Expected one value, found 0')
E   executing.executing.NotOneValueFound: Expected one value, found 0

During handling of the above exception, another exception occurred:
tests/test_main.py:682: in <module>
    assert tester([1, 2, 3]) == [1, 2, 3]
tests/utils.py:40: in __call__
    ex = self.get_executing(inspect.currentframe().f_back)
tests/utils.py:28: in get_executing
    return Source.executing(frame)
executing/executing.py:369: in executing
    args = find(source=cls.for_frame(frame), retry_cache=True)
executing/executing.py:355: in find
    return find(
executing/executing.py:346: in find
    node_finder = NodeFinder(frame, stmts, tree, lasti)
executing/executing.py:636: in __init__
    matching = list(self.matching_nodes(exprs))
executing/executing.py:702: in matching_nodes
    original_index = only(
executing/executing.py:164: in only
    raise NotOneValueFound('Expected one value, found 0')
E   executing.executing.NotOneValueFound: Expected one value, found 0
========================================================================= short test summary info ==========================================================================
ERROR tests/test_main.py - executing.executing.NotOneValueFound: Expected one value, found 0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================= 1 error in 0.44s =============================================================================
@alexmojaki
Copy link
Owner

The magics of pytest and executing interfere with each other, so test_main cannot be run with pytest. See the commands in tox.ini:

    python tests/test_main.py
    pytest tests/test_pytest.py

@kloczek
Copy link
Author

kloczek commented Apr 6, 2022

It would be really good to adapt test suite to be able use it with pytest as it provides far greater flexibility of altering testing procedure without touching tested code by just install pytest extension.

@alexmojaki
Copy link
Owner

I'm saying that executing itself doesn't work properly in lines like assert foo(a) == b in the presence of pytest. It can't identify if the node foo(a) is executing because pytest transforms the line and actually runs much more than assert foo(a) == b.

@kloczek
Copy link
Author

kloczek commented Oct 10, 2022

Just tested 1.1.1 and now all looks good.
Thank you 👍

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-executing-1.1.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-executing-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.14, pytest-7.1.3, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/executing-1.1.1
collected 58 items

tests/test_main.py ................................sssssssssssssss.                                                                                                  [ 82%]
tests/test_pytest.py ..........                                                                                                                                      [100%]

========================================================================= short test summary info ==========================================================================
SKIPPED [14] tests/test_main.py:679: These tests are very slow, enable them explicitly
SKIPPED [1] tests/test_main.py:695: These tests are very slow, enable them explicitly
===================================================================== 43 passed, 15 skipped in 12.49s ======================================================================

@alexmojaki
Copy link
Owner

Thanks to @15r10nk for his work in #51, specifically disabling rewriting which I didn't know was an option.

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