autotest: Fall back to relative imports in pytest discovery#30444
autotest: Fall back to relative imports in pytest discovery#30444cclauss wants to merge 1 commit intoArduPilot:masterfrom
Conversation
6dad45d to
2202f2c
Compare
|
These are not designed for relative imports as you can see from the CI errors. Is there a way to warn users who try to do a global discovery that the project is not designed for it? And point them to our test scripts instead? There's this implicit assumption you are making that |
|
When a change is proposed, we want to add tests that can be found and run automatically. What I was looking for was a GitHub Action that detects new tests based on naming conventions. If we need to |
|
That is what the autotest framework is for: https://ardupilot.org/dev/docs/the-ardupilot-autotest-framework.html If you are proposing e.g. testing that framework itself, which is not unreasonable, we probably need a dedicated directory for that and to always point pytest there. But currently For better or worse, the current tests for the build system and the autotest framework are generally just CI, i.e. the things that use them. Plus a culture to think through and manually exercise changes (e.g. We could always use more testing but I think it needs a more principled and tailored approach than making the whole project |
2202f2c to
326bbca
Compare
326bbca to
13b7069
Compare
edfbeab to
ddb3b37
Compare
|
ddb3b37 to
9ceb638
Compare
peterbarker
left a comment
There was a problem hiding this comment.
Needs to pass CI.
@robertlong13 will need to be happy with the changes to the parameter extraction test stuff.
Tools/autotest/test_param_upgrade.py
Outdated
| try: | ||
| import vehicle_test_suite | ||
| from pysim import util | ||
| except (ImportError, ModuleNotFoundError): # Fall back to a relative import in pytest | ||
| from . import vehicle_test_suite | ||
| from .pysim import util |
There was a problem hiding this comment.
I'm really concerned about bending our code to suit a new tool like this.
ArduPilot is not a Python project. I'm not sure we should be conforming to the conventions of one.
Can pytest be configured via a file in the root directory to ignore these files instead of modifying them here?
c1a6167 to
8e9f8a0
Compare
`Tools/autotest/test_build_options.py` and `Tools/autotest/test_param_upgrade.py` have filenames that will cause Pytest Discovery to think they should be tested, but these files do not contain Python `unittests` or `pytest` tests. * https://docs.pytest.org/en/stable/explanation/goodpractices.html#conventions-for-python-test-discovery These files also import `pysim` and `vehicle_test_suite` from the same directory, but do not use relative imports, so pytest raises errors. The proposed change is to use relative imports: ```diff - from pysim import util + try: + from pysim import util + except ImportError: # Fall back to a relative import in pytest + from .pysim import util ``` Searches for these files: * https://github.com/search?q=repo%3AArduPilot%2Fardupilot%20test_build_options.py&type=code * https://github.com/search?q=repo%3AArduPilot%2Fardupilot%20test_param_upgrade.py&type=code How was this tested? % `uv tool run --python=3.12 --with=MAVProxy --with=numpy --with=pexpect pytest Tools/autotest` Warnings were raised instead of crashing with a confusing error.
8e9f8a0 to
958897a
Compare
Tools/autotest/test_build_options.pyandTools/autotest/test_param_upgrade.pyhave filenames that will cause Pytest Discovery to think they should be tested, but these files do not contain Pythonunittestsorpytesttests.These files also import
pysimandvehicle_test_suitefrom the same directory, but do not use relative imports, so pytest raises errors.The proposed change is to use relative imports:
Searches for these files:
How was this tested?
%
uv tool run --python=3.12 --with=MAVProxy --with=numpy --with=pexpect pytest Tools/autotestWarnings were raised instead of crashing with a confusing error.