https://pantsbuild.org/ logo
#general
Title
# general
f

fresh-continent-76371

03/18/2023, 11:11 AM
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
//:reqs#..
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.
1
r

refined-addition-53644

03/18/2023, 11:15 AM
Have you already tried options
--keep-sandboxes
and
-ldebug
? https://www.pantsbuild.org/docs/troubleshooting
If you post some error log maybe we can provide more help also.
b

broad-processor-92400

03/18/2023, 11:17 AM
What’s the error? Have you seen the “debugging tests” section of https://www.pantsbuild.org/docs/python-test-goal too?
f

fresh-continent-76371

03/18/2023, 11:38 AM
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.
    
        Parameters
        ----------
        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.
    
        Returns
        -------
        str
            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)
        else:
            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
r

refined-addition-53644

03/18/2023, 11:46 AM
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?
f

fresh-continent-76371

03/18/2023, 12:08 PM
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/
r

refined-addition-53644

03/18/2023, 12:14 PM
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.
f

fresh-continent-76371

03/18/2023, 12:19 PM
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
r

refined-addition-53644

03/18/2023, 12:22 PM
So much magic!
f

fresh-continent-76371

03/18/2023, 12:23 PM
Copy code
'/tmp/pants-sandbox-BKuk2N/computing_high/instruments/sim/Agilent_E8267D.yaml'
yep that is what it is
So .. I thought this would work
Copy code
resources(
    name="test_resources",
    sources=["**/test/**/*.json","**/test/**/*.yaml","computing_high/instruments/sim/**/*.yaml"]
)

python_tests(
    name="tests",
    sources=[
        '**/test_*.py', '**/*_test.py',
        ],
    dependencies=[
        ":test_utils",
        "//:setuptools",
        ":test_resources",
        "//:reqs#PyVISA",
        "//:reqs#PyVISA-sim",
    ]

)
r

refined-addition-53644

03/18/2023, 12:28 PM
How is path being inferred by the package when loading these files?
f

fresh-continent-76371

03/18/2023, 12:35 PM
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
2 Views