-
Notifications
You must be signed in to change notification settings - Fork 33
Feat/rfct/pytest3 #770
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
Feat/rfct/pytest3 #770
Conversation
kba
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again! You're probably right, it's best to inject these into the object rather than relying on "constants" that need to be changed for testing. The final testing code is much more readable like this. I also discovered monkeypatch today, this is extremely useful, e.g. for mocking sys.stdin etc. Looking forward to using that once we completely migrated to pytest :)
e19191f to
d7de707
Compare
|
Must confess I usually do not have an account-global logging configuration, I pass it straight into the working directory for each OCR-D-Workflow. Please can you provide some more details on how the regression turns out and how one might reproduce this? |
|
Of course: take the default Line 64 in 9567190
consoleHandler to sys.stdout instead of stderr.
|
|
Thanks! Plz give me some time to take a closer look to the mentioned test module |
This refactoring of test_resource_manager is also meant as proposal to reduce the environmental and internal dependencies in the ocrd-modules.
As @kba pointed out, there's actually a strong dependency between the resource_manager-module to the time, when the constants
XDG_CONFIG_HOMEandXDG_DATA_HOMEare loaded / evaluated.The trouble with testing the resource_manager originates from the - somehow intransparent - relationship to the execution environment i.e. context - intransparent to the caller in the moment of execution, which makes it difficult to test any depending functionalities, since testing is a rather artificial execution. The rather plain "workaround" for this bias is the possibility to pass these this info to the objects which require them, as properties or at initialization time. I found myself often ending up in implementations like this, which only exist to ease testing purposes and nothing else.
This way there's no need to run the three resource_manager tests separate from regular unit tests.
Personally, I tried even to go further this line, which simply results in having no "constant" values for
HOMEor the xdg-stuff, but rather evaluated both only when they are really required, but this interferes with other modules - os.py and bashlib.py, the latter which I do not yet understand.