Closed pauleveritt closed 5 years ago
@mmerickel I think the answer here is to make venusian an argument, rather than an import?
You need to monkeypatch it at the place it's imported. For example if a module does from venusian import Scanner
then it's a local variable in that module, so you need to modify it there. For example monkeypatch.setattr(module, 'Scanner', DummyScanner())
.
It always seems to be too far way for me to catch the import, or at least it was last time. Something wound up importing wired.dataclass
which then imported venusian. I'll try again, thanks.
Well the question is which specific reference to the scanner you're trying to patch. It's basically always a question of patching the reference in the module that's using the object/class.
I have a test that tries to use a monkeypatch to assert calls to the scanner.
However, I can't seem to intercept
venusian.scanner
correctly. No matter what, it seems something else is importing it before I get a chance at it. Any suggestions?