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

do not import unittest if mock is disabled #1096

Closed
wants to merge 1 commit into from
Closed

do not import unittest if mock is disabled #1096

wants to merge 1 commit into from

Conversation

lonepig
Copy link

@lonepig lonepig commented May 22, 2023

I am working on an embedded Linux, whose python does not have unittest module supplied,
I moved the import statements, if use_mock is True, then do import

@svinota
Copy link
Owner

svinota commented May 22, 2023

But do you need this lab module at all in an embedded environment? The proposal looks rather like a workaround, and I believe there may be a more proper way to provide the required functionality.

Does the minimal build work for you? If not, what's missing?

If you could share the requirements, I would either adjust the minimal build, or create a separate build for your requrements.

@lonepig
Copy link
Author

lonepig commented May 23, 2023

No, I do not need the lab module.
I use pyroute2 for DiagSocket, the first import pyroute2 would cause an import for unittest,
I guess importing IPRoute module can not be avoided, is there any other way can work without importing IPRoute?
I have tried the minimal build, the same thing happened.

    from pyroute2 import DiagSocket
  File "/home/root/pyroute2/__init__.py", line 16, in <module>
    from pyroute2.cli.console import Console
  File "/home/root/pyroute2/cli/console.py", line 7, in <module>
    from pyroute2.ndb.main import NDB
  File "/home/root/pyroute2/ndb/main.py", line 300, in <module>
    from .view import SourcesView, View
  File "/home/root/pyroute2/ndb/view.py", line 72, in <module>
    from .source import Source, SourceProxy
  File "/home/root/pyroute2/ndb/source.py", line 82, in <module>
    from pyroute2.iproute import IPRoute
  File "/home/root/pyroute2/iproute/__init__.py", line 133, in <module>
    from pyroute2.iproute.linux import RTNL_API, IPBatch
  File "/home/root/pyroute2/iproute/linux.py", line 13, in <module>
    from pyroute2.lab import LAB_API
  File "/home/root/pyroute2/lab.py", line 2, in <module>
    from unittest import mock
ModuleNotFoundError: No module named 'unittest'

@svinota
Copy link
Owner

svinota commented May 23, 2023

Oke, let me see how to help in this situation. I believe this week we will fix it.

@svinota
Copy link
Owner

svinota commented May 29, 2023

Sorry for delay, I'm fixing this tonight.

svinota added a commit that referenced this pull request May 29, 2023
The issue is that unittest may not be provided on embedded platforms,
though it is included in the minimal build. This is a workaround, a
proper fix should exclude lab module from the minimal build.

Bug-Url: #1096
@svinota
Copy link
Owner

svinota commented May 29, 2023

Merged the fix, please check if it works for you: #1100

When you confirm it working, I'll roll out a minor release for that.

@lonepig
Copy link
Author

lonepig commented May 30, 2023

Merged the fix, please check if it works for you: #1100

When you confirm it working, I'll roll out a minor release for that.

It works!

@svinota
Copy link
Owner

svinota commented May 30, 2023

Thanks for the feedback! I close this PR, and the release will be ready tonight.

@svinota svinota closed this May 30, 2023
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.

2 participants