i have a scenario where a pytest works, but within...
# general
i have a scenario where a pytest works, but within pants, the 3rd party library throws quite an obscure error. thinking it may be a module that is missing, I added all
to the test, but that did not resolve it. what is the best way to debug this issue (I have 15 test cases that fail for -not same- reasons, so I am after the technique suggestions.
Have you already tried options
? https://www.pantsbuild.org/docs/troubleshooting
If you post some error log maybe we can provide more help also.
What’s the error? Have you seen the “debugging tests” section of https://www.pantsbuild.org/docs/python-test-goal too?
The error won't help much 🙂 What the cause is this is a test that utilises a "simulated" PyVISA device driver, using PyVISA-sim. but I suspect that the PyVISA-sim module is not loading in; or some resource associated to that
Copy code
/home/USER/.cache/pants/named_caches/pex_root/venvs/s/426ec880/venv/lib/python3.9/site-packages/pyvisa/resources/messagebased.py:644: in query
    return self.read()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <'GPIBInstrument'('GPIB0::19::0::INSTR')>, termination = '\n'
encoding = None

    def read(
        self, termination: Optional[str] = None, encoding: Optional[str] = None
    ) -> str:
        """Read a string from the device.
        Reading stops when the device stops sending (e.g. by setting
        appropriate bus lines), or the termination characters sequence was
        detected.  Attention: Only the last character of the termination
        characters is really used to stop reading, however, the whole sequence
        is compared to the ending of the read string message.  If they don't
        match, a warning is issued.
        termination : Optional[str], optional
            Alternative character termination to use. If None, the value of
            write_termination is used. Defaults to None.
        encoding : Optional[str], optional
            Alternative encoding to use to turn bytes into str. If None, the
            value of encoding is used. Defaults to None.
            Message read from the instrument and decoded.
        enco = self._encoding if encoding is None else encoding
        if termination is None:
            termination = self._read_termination
            message = self._read_raw().decode(enco)
            with self.read_termination_context(termination):
                message = self._read_raw().decode(enco)
        if not termination:
            return message
        if not message.endswith(termination):
>           warnings.warn(
                "read string doesn't end with " "termination characters", stacklevel=2
E           UserWarning: read string doesn't end with termination characters
How does your import statement look like for this package? Does the import statement you use for the package starts with the same name as the name of the package?
It is 3rd party code, so I am debugging it at the moment. what I know is ; a different module loads when you use their API . https://pyvisa.readthedocs.io/projects/pyvisa-sim/en/latest/
You can try using string import option. Not sure if that will figure it out. https://www.pantsbuild.org/docs/reference-python-infer#string_imports Although their import syntax with
is kinda weird.
okay - i am closer - looks like the test file is loading or is invalid (a YAML file) which fakes the instrument.
yep that is what it is. The file is not in the sandbox I think
So much magic!
Copy code
yep that is what it is
So .. I thought this would work
Copy code

        '**/test_*.py', '**/*_test.py',

How is path being inferred by the package when loading these files?
found it
🙂 the path was inferred correct, i had "context" error as to where the BUILD file was, and how I was including the test files (they were not in the sanbox at all)
🎉 1
thanks for the help (i used the debug params to attached the vscode debuger to locate what was going on)
🙌 1
the debug tip was on that page 🙂 that @broad-processor-92400 suggested. . ta
👍 1