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
Feature/test inventory #30707
Feature/test inventory #30707
Conversation
|
i actually added a yaml inventory file to testing so we could use it to run the other tests (uses ini now, but could split the load) .. but it got moved to legacy :-( |
| @mock.patch('os.access') | ||
| def test_yaml_inventory(self, p_access, p_exist): | ||
| inventory_content = """ | ||
| --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
textwrap.dedent could be used here.
|
The unit test should be self-contained, so having it provide its own inventory is good. |
|
not an 'either/or' ... part of testing the plugin is seeing that the |
|
Using files in unit tests is fine. However, those files should be stored alongside the unit tests instead of shared with integration tests. Mixing the two complicates dependency analysis when looking at changes to determine which tests to execute. |
|
@pilou- improved code |
| @@ -173,7 +173,7 @@ def test_yaml_inventory(self): | |||
| """)} | |||
| C.INVENTORY_ENABLED = ['yaml'] | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pilou- C.INVENTORY_ENABLED must be reset after using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The new method is inside IniInventory class, it could be moved in another class (YamlInventory ?), then setUp and tearDown methods could be used in order to 1. save, 2. set (in setUp) and 3. restore (in tearDown) C.INVENTORY_ENABLED.
|
@mattclay good point, i was trying to leverage the file but it does make cross dependencies that I didn't realize |
|
The test |
|
code lgtm, reorg .. i'll let @mattclay decide |
* [test] move inventory test to right path * [feat] add unit test for yaml inventory plugin
SUMMARY
Adding unit test for yaml inventory plugin related to #30663
ISSUE TYPE
COMPONENT NAME
test/units/plugins/inventory/test_inventory.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
After change