-
Notifications
You must be signed in to change notification settings - Fork 283
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
CA-390883: Move usb_reset.py to python3, test mount() in a namespace #5565
CA-390883: Move usb_reset.py to python3, test mount() in a namespace #5565
Conversation
Thanks for opening this, I've changed the base branch to feature/py3 |
sys.modules.pop(module_name) | ||
|
||
|
||
def import_file_as_module(relative_script_path): # type:(str) -> ModuleType |
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.
this file is duplicated with https://github.com/xapi-project/xen-api/blob/feature/py3/python3/unittest/import_file.py
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.
Not quite, this one provides more functionality
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.
I've prepared a branch that deletes import_file.py: feature/py3...psafont:xen-api:test-and-fix-usb_reset-mount
currently python3 folder has sub-folders as
|
Use a rootless container (like unshare --map-root-user --mount) to test the correct calling convention for mount()/umount(). Use a context manager test fixture to temporarily mock module imports: This allows to mock global modules only temporary for importing the testee without affecting other tests. - Add a sufficient testcase to test usb_reset.py: mount() and umount() without mocking the system or library calls in any way. - Use python3/tests a Python tests package to allow for non-deprecated relative imports: Absolute imports within a module are deprecated. Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
50e7168
to
69338c5
Compare
Bernhard Kaindl: Resolved a conflict with one of my other upcoming changes which removes the need to a pytype ignore by using a cast() instead, which fixes pyright/pylance/vscode. Also keep import_helper in python3/tests as the the name "unittest" sould likely avoided as it clashes with the unittest module. The tests in python3/tests are written for pytest instead and not all of them will classify as unit tests, so using the name unittest for them would also be a misnomer. Using the name tests is shorter and more generic, and we can also use the separation beween tests and unittest to differentiate between modern pytest tests and legact unittest-based tests which should possibly be better migrated to pytest at some point for the benefits that pytest gives: For example with pytest, you can use use just assert and you do not need to use self.assert...(), because pytest implements the proper assert matching diagnostics. In the long run, the classic unittest tests should no longer be used. Co-authored-by: Bernhard Kaindl <bernhard.kaindl@cloud.com> Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com>
69338c5
to
2bf2a44
Compare
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.
tests
and unittest
folder can be combined,
I approve this PR for now, @stephenchengCloud Could you please help on this at proper time.
Sure, I'll raise another PR for this. |
pytype_reporter extracted 33 problem reports from pytype output. You can check the results of the job here |
This is the requested follow-up from #5401 (CA-390883: Add unit test for usb_reset.py)
The only changes in this PR compared to #5401 which was closed due to inactivity are:
scripts/usb_reset.py
topython3/libexec/usb_reset.py
.github/workflows/main.yml
that were merged using another PR.#5401 was approved by linliu, and the only remaining request was by @psafont:
Done now.