Consistent error messages #1159
-
Hello, I am not sure if this is the right place to tell this, but I noticed the error messages raised by different mocked functions in pyfakefs raise different error messages, like in these examples below:
The first test passes successfully, but the second test fails this way:
This is not really an issue, as I can check "[Errno 13] Permission" is in the error message, as well as the directory name. I also suppose that replacing [Errno 13] Permission denied in the fake filesystem with [Errno 13] Permission Denied would be a problem, as it might break already written tests relying on the original message. Moreover, in some places, especially when one handles both fake and real files in the same test, it proves useful to be able to make the difference between error messages from the fake and from the real filesystem (I mean, the real python functions). Still, I wonder if there is a special reason why these two (from copy2() and move()) messages differ. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Actually this is a good point. I think the intention at the time was to make clear that the message comes from the fake fs, to distinguish them from accidental access to the real fs (but you will see this anyway in the callstack). Also, having the addition at the end makes it possible to check the error messages using But - as you have noticed, this is not consistent, because there are several places where the exception is not raised using the method to raise an OS exception, as is the case here. message = os.strerror(err_no) + " in the fake filesystem" Obviously, at the time I didn't replace all the occurences of manually adding the error message, there are still a few instances where an So, I think what I will do is replacing these instances with the generic call, and probably get rid of the " in the fake filesystem" part. I very much doubt that anybody is relying on this, though the change has to be documented, of course. Let me know if this would be ok for you. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the delay, yes this is OK! |
Beta Was this translation helpful? Give feedback.
Actually this is a good point. I think the intention at the time was to make clear that the message comes from the fake fs, to distinguish them from accidental access to the real fs (but you will see this anyway in the callstack). Also, having the addition at the end makes it possible to check the error messages using
startswith
.But - as you have noticed, this is not consistent, because there are several places where the exception is not raised using the method to raise an OS exception, as is the case here.
Note also that in this case the capitalization differs - this is because in the first (passing) case the message has been hard-coded, while in the second case in is taken using
os.str…