Replies: 1 comment
-
Hi @aroberge, pytest being a framework will call your tests from its own stack, so there's not much that can be done in that regard. However your test passes if you do a simple change: for key in list(frame.f_locals): It is curious though why the locals are changing, seems to be happening in |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
This is half a Bug report and half a Feature request. It is a bug report as a test that runs fine on its own generates a
RuntimeError
when run with pytest. It is a Feature request in that I would be happy to use simply mark such tests as collected by pytest but run "as is", without additional pytest magic. I have posted a minimal example on StackOverflow which I reproduce here.Stack Overflow post
Is there a way to use pytest as a test runner to collect some unit tests but prevent pytest from modifying the test code itself on selected unit tests?
As part of a series of unit tests in Python, I have some that use functions that rely on frame inspection. If I run these on their own, they produce the expected results. However, if I use pytest to collect the tests and run them, the tests fail as pytest inserts additional frames which end up generating a
RuntimeError
.Here's a sample file that works when run on its own using only Python. I added a print statement so as to show one of the frames added by pytest before an exception was raised.
First, the result of simply using "python test.py"; no exception is raised.
Next, running the same file with
pytest test.py
Environment details
pytest and operating system versions
Python 3.8.3 on Windows 10
pytest 6.1.1
output of
pip list
from the virtual environment you are usingSee above.
See above.
Beta Was this translation helpful? Give feedback.
All reactions