-
Notifications
You must be signed in to change notification settings - Fork 145
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
launch_testing test file import can cause confusing module import issues #357
Comments
I can't recall why didn't we simply do |
@pbaughman are you planning to send a patch to address this issue? It seems straightforward. |
@hidmic Yeah, let me see if I can find a moment to do it. I need to be a little careful to do this in a way that doesn't change the resulting XML files because we have a whole test-history infrastructure built up where the test name is the unique key. People are going to be very upset at me if a quarter of our tests suddenly have different names and now it's hard to see the history |
@hidmic I need to think about this some more, or I'm going to cause all our tests to get renamed. The module name we choose here gets included as part of the classname in one of the junit XML elements here If I change it (for example, to foo), then a test with a name like
becomes
|
I wonder if there's a way to do |
@hidmic I can preserve the existing test names and fix the issue by doing:
This tries to import any 'real' modules that have the same name as test_module_name, so any subsequent 'import' statements get the real one instead of the test-file-as-a-module one. On a scale of good to awful, where do you think this lands? I wonder if we should worry about side-effects from importing |
It's not pretty, but I don't see a lot of other options. You could tinker with
Yeah, there's that. Ideally, loading a test module shouldn't have any side effects. |
@hidmic I tried to mess about with sys.modules, but there was no good place to do it. When this errors out, loader.load_module() from launch_test.py is in the stack. We'd have to do major surgery on the SourceFileLoader to fix it that way, I think. . . Anyway, I'll open a PR with the 'load the real one early' fix |
Bug report
Required Info:
Steps to reproduce issue
We have a package called
lidar_integration.
This package installs a python module also called lidar_integration and it has some tests that run withros2 test.
The test file is calledfoo_test.py
When we run the test with
colcon test
or withros2 test foo_test.py --package_name lidar_integration
we get a bizarre import error that was difficult to debug, but easy to understand once we figured out what's going on. The test tries to doBut then fails with someting like (sorry, error message is from memory)
Because of the way the test file was imported by launch_testing here, when you import lidar_integration from the test, instead of getting the lidar_integration module which contains
useful_tool
, you get test file which was named 'lidar_integration' when it was imported becauselidar_integration
is the package name and that was used to name the module when the SourceFileLoader loaded itExpected behavior
I'm not sure, exactly. I wanted to get @hidmic 's opinion on this. If you run the test with ros2 test foo_test.py, there's no problem becaues when we import the test file we name it
foo_test
.foo_test
doesn't collide with any modules names so there's no problem.I suspect we use the package name as the module name because this information makes it into the junit XML generated by launch_testing (I'm speculating based on the git blame history of this line). I have not yet investigated what happens to the junit XML if I change the name of the imported test file.
Additional information
I want your take on how to solve this problem. My ideas thus far are
test_lidar_integration
The text was updated successfully, but these errors were encountered: