Skip to content
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

Conversation

bernhardkaindl
Copy link
Collaborator

@bernhardkaindl bernhardkaindl commented Apr 17, 2024

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:

  • Move scripts/usb_reset.py to python3/libexec/usb_reset.py
  • Removed the Python2 compatibility (as requested by @psafont)
  • Removed the needed changes to .github/workflows/main.yml that were merged using another PR.

#5401 was approved by linliu, and the only remaining request was by @psafont:

It'd be nice to get this merged into the feature branch, can the testing for python 2 be dropped?

Done now.

@psafont psafont changed the base branch from master to feature/py3 April 17, 2024 10:09
@psafont
Copy link
Member

psafont commented Apr 17, 2024

Thanks for opening this, I've changed the base branch to feature/py3

@bernhardkaindl bernhardkaindl requested review from liulinC and freddy77 and removed request for edwintorok April 17, 2024 10:16
sys.modules.pop(module_name)


def import_file_as_module(relative_script_path): # type:(str) -> ModuleType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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

Copy link
Member

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

@liulinC
Copy link
Collaborator

liulinC commented Apr 19, 2024

currently python3 folder has sub-folders as

  • tests
  • unittest
    @stephenchengCloud will combine these into one when it is the time for the feature merge.
    Given this PR target to feature/py3 now, I suggest the test goes to unittest and re-use import-file

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>
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>
Copy link
Collaborator

@liulinC liulinC left a 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.

@stephenchengCloud
Copy link
Contributor

@stephenchengCloud Could you please help on this at proper time.

Sure, I'll raise another PR for this.

@bernhardkaindl bernhardkaindl merged commit dabc634 into xapi-project:feature/py3 Apr 26, 2024
13 checks passed
Copy link

pytype_reporter extracted 33 problem reports from pytype output

.

You can check the results of the job here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants