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
Importing fipy raises error when testing with pytest in vscode (--cache-clear) #895
Comments
This has nothing to do with The actual source of the problem is that pytest appears to have monkey-patched optparse. FiPy is trying to check its command-line options and pytest is interfering (cf. "pytest: error: no such option: --cache-clear"). As to |
Actually, I should clarify that I don't know that pytest did the monkey-patching. In fact, if I had to guess, vscode is probably the culprit. |
Thanks for your quick reply. @guyer It is not the IDE but pytest itself since running the above mentioned command in a cli yields the same error. @guyer I guess you are right about that import* not being the problem here because an explicit import will trigger the same code which will yield the same problem. (And whether it is pep compliant is not too relevant as long as things work as expected I would say) I understand the code is written along time ago with the legacy artefacts that this brings. No intrinsic problem here. That is why I asked for hints for a workaround and not a fix from your side (especially since this seems to be an edge case). @wd15 thanks for your suggestion for a workaround. Do you suggest to fork the code and alter the code there? Of should I something similar in my code to swallow the sysarg before importing fipy? In his regard, i wondered why fipy is parsing sysargs anyway when the package is imported in a python file . Seems to me that this is only necessary in some cases. |
That's what I was thinking, but no idea if it will fix your problems. Jon seems to suggest that something else is going on. Trying won't hurt, however.
That would be preferable to hacking FiPy from your perspective. Try and see what happens.
Again, it's the legacy thing. We might deal with this in a different way now. We wanted to able to run
for example, and use the pysparse solver suite or any one of a myriad of other choices. Nowadays, we'd probably go with a config file or some other more consistent system that doesn't turn FiPy into a command line tool. However, as @guyer pointed out, it might not be FiPy causing the issue in your case. |
Ok thanks for confirming. I will try after the Christmas holidays. |
That's helpful to know, thank you |
I am using fipy to run some simple 1D convection-reaction model. This is part of a larger model suite and as such it needs to be automatically (unit) tested. We do that with pytest. This works well, unless I run pytest with --cache-clear argument.
This is very annoying because my IDE (vscode) run the tester with this command. It seems like the --cache-clear argument is swallowed by the argument parser of fipy which raises the "BadOption" error. I have the feeling it has to do with the
import *
in the fipy files which is as far as I understood, not adviced to (according to PEP8 I believe). Any idea for a workaround?It returns the error:
pytest 7.2
python 3.9
fipy 3.4.3
The text was updated successfully, but these errors were encountered: