-
Notifications
You must be signed in to change notification settings - Fork 91
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
problem with os.stat
within eyed3.load
when running multiple tests using fs
based fixture
#1105
Comments
Thanks for the report! |
If using your code with a dummy I would need a bit more information to be able to reproduce this, ideally a self-contained example, as I wrote above. |
Hi, I'll try to provide a minimal example tomorrow. |
Hi @mrbean-bremen , here is a minimal example that raises for me:
Each test running in isolation succeeds. But executing both tests in a sequence raises:
As you can see it complains |
Thanks a lot, I now can reproduce the problem! Still a bit at a loss as to the cause, but I will see what I can find. |
Thanks a lot in advance! And good luck :-) |
I'm quite sure that this is a bug in pyfakefs regarding the patching of @pytest.fixture
def test_fs():
with Patcher(use_dynamic_patch=False) as patcher:
yield patcher.fs as your fixture. This will fix the minimal test, but the dynamic patcher may still be needed for other tests, so this may or may not help you. |
I kind of got stuck with this issue, as I could not find an automatic fix for the problem, and I'm not sure if I will find one - I currently consider this a limitation of def reload_cleanup_handler(name):
if name in sys.modules:
importlib.reload(sys.modules[name])
return True
@pytest.fixture
def test_fs():
with Patcher() as patcher:
patcher.cleanup_handlers["eyed3.mimetype"] = reload_cleanup_handler
yield patcher.fs I've also made a PR (now merged) that adds this specific Note that in an earlier version I had done this reload to all dynamically loaded modules, but that turned out not to be a good idea because of certain unpredictable side effects in some modules. |
Thank you very much for your efforts. I'll give your convenience function a try this week. Thanks |
FYI: I just made a patch release which contains these changes (among a couple of other fixes). |
Hi @mrbean-bremen , I just updated pyfakefs to the latest patched version but ... unfortunately I am not quite sure what I need to implement to make it work. I think I need to follow your advice for dynamic patcher with patching a module (https://pytest-pyfakefs.readthedocs.io/en/latest/troubleshooting.html#tests-failing-after-a-test-using-pyfakefs). Returning to the minimal example with eyed3: Is the module my module that uses eyed3 or is it eyed3 or something within eyed3? Thanks! |
It is actually from pyfakefs.helpers import reload_cleanup_handler
@pytest.fixture
def test_fs():
with Patcher() as patcher:
patcher.cleanup_handlers["eyed3.mimetype"] = reload_cleanup_handler
yield patcher.fs |
I would still like to have that done automatically, but I haven't figured out a way to do this yet. |
Thanks though for the manual way. But I still do not get it up and running. Maybe in my case I need some more patching... Since these tests pass in single mode I will maybe wait for an automatic solution. For my own reference: https://github.com/stevenengland/dfplayer_card_manager/blob/89ce0d9c6497b4755a28ed3e15066bbef7b23a51/tests/conftest.py#L20 |
Ok, I will have a look at your project a bit later. |
Can you point to the tests that fail in your project and pass if run in single mode? I'm trying to reproduce the problem in your repo. |
Describe the bug
Hello together, I have hard times finding out what causes the following error: I am using the
fs
(notfs_module
etc. -> fs) inside a fixture. There is one test, that, when ran in isolation, succeeds. But when it runs together (sequentially) with any other test that uses thefs
based fixture it fails.TLDR
Of course the first thought is, are there any other filesystem actions colliding with the test but I think i ruled those out:
1:
fs
is used on a per test basis (as far as I can read from the docs onlyfs_module
etc. are scoped broader than function, right?)2: I added some debugging lines that verify the existence of the file which a code line later causes a fail. Also, before the failing line
os.stat
is called withineyed3.load
method, eyed3 performs some internal checks likeif not path.is_file()
that are passed. So the pure existance of the file should be given I think. more can be read here: https://github.com/nicfit/eyeD3/blob/2cdef0d7542e65cc2756d63c2afffbdf48061eea/eyed3/mp3/__init__.py#L93How To Reproduce
This is the test setup and test code up to the point where it raises:
The following code is where it leaves my codebase and raises the error within eyed3:
The resulting debugging output is this:
The error thrown/stacktrace is:
Your environment
Windows-11-10.0.22000-SP0
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
pyfakefs 5.6.0
pytest 8.2.1
does such a scenario ring a bell of someone? What can I do to further track down the issue?
Kind regards!
The text was updated successfully, but these errors were encountered: