-
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
How to use with setUpClass() #752
Comments
No, there is no specific support for that. It is assumed that the setup is fast enough to happen in each test, and so far, this has not been an issue. |
Actually, on a second thought, it makes probably sense to add a class method for setup. As I recently changed the implementation to allow only one patched instance (this was made for session or module scoped fixtures in pytest), this will allow to access the fake filesystem via |
I had another look at this, and while I can add a convenience function for class setup (I did this locally), it may not behave as expected. It would ehave the same way as creating the patcher in the class setup, as shown in the original comment. That would also mean that any changes to the file system in a single test would persist, so the test would influence each other. |
😄 I think that you think way to far. 😀 I'm aware that the each test can (theoretically) influence each other. But a developer who write unittest should know that. It is his/her responsibility and not yours. You can give a note about that in your documentation but that is IMHO enough. I see definitely no need for a reset- or snapshot-feature. In my case all unittests only reading from the file system. Thats all. They don't write to it. So I see no problem. |
Thanks!
Well, if you say so 😀 |
I added the class method |
Dear @mrbean-bremen , I can confirm that #758 does work. You can see it in real world here. |
From the documentation it is not clear how I can use PyFakeFS in a setUpClass().
setuppyfakefs()
only works with aself
instance from asetUp()
method.My current solution is to use a
Patcher
object insetUpClass()
like this:Maybe you know a better way?
You could improve the "Usage" section of the docu with an situation using
setUpClass()
.My use-case:
I do create some testfiles in the fake filesystem. Because I only want to read them in the tests I need to create them only once for all tests. Creating them for each test again and again is ressourc inefficient.
The text was updated successfully, but these errors were encountered: