You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tests are shipped as a module with the package #140
tests directory is shipped as part of the package. This can be a problem, since many projects contain a tests directory themselves. For example, this can be a problem for projects that import from their tests directory while running the tests.
The reason for this is that the module tests is now ambiguous; it refers both to tests in the virtual environment, and to the tests directory in their project. This will lead to errors while running the unit tests like:
ModuleNotFoundError: No module named 'tests.utils'
The issue can be confirmed with the following steps:
Thanks for the catch. I intend to merge your PR #139 for cleaning purpose, if nothing else.
Out of curiosity, how bad is it for the shipped MSAL EX 1.3.0, though? Do we have to ship this fix quick? What actual issue did you run into, Florian Maas (@fpgmaas) , Michael Kuth (@mpkuth)? I did some quick tests, and it seems a project can still pick up their own tests folder.
py311demo@antix1:/tmp$ python -c "import tests as t; print(t)"
<module 'tests' from '/tmp/tests/__init__.py'>
py311demo@antix1:/tmp$ cd dir_without_tests
/tmp/dir_without_tests
py311demo@antix1:/tmp/dir_without_tests$ python -c "import tests as t; print(t)"
<module 'tests' from '/home/demo/Live-usb-storage/repo/microsoft-authentication-extensions-for-python/.tox/py311/lib/python3.11/site-packages/tests/__init__.py'>
UPDATE:
The example in my tests above used a tests folder with a __init__.py file, and the import was able to locate it first, regardless of whether a package tests exists in site-packages. But if I remove that __init__.py file, the import indeed hits the package tests exists in site-packages. This subtle import behavior difference is likely the root cause.
py311demo@antix1:/tmp$ rm tests/__init__.py
py311demo@antix1:/tmp$ python -c "import tests as t; print(t)"
<module 'tests' from '/home/demo/Live-usb-storage/repo/microsoft-authentication-extensions-for-python/.tox/py311/lib/python3.11/site-packages/tests/__init__.py'>
Ray Luo (@rayluo) For some of my projects it breaks the CI/CD pipelines. I created a small reproducible example here. The unit tests succeed without msal-extensions, but they fail when msal-extensions is added as a dependency.
There are some workarounds of course;
I can pin msal-extensions to 1.2.0 since the latest version of azure-identity depends on >=1.2.0
move tests.utils to test_utils.
So it is not very urgent, but I still think a 1.3.1 release would be nice to release quickly in this case to prevent users of the package from having to modify their projects.
Thanks Florian Maas (@fpgmaas) for going extra mile to set up a repo for repro. And thanks Michael Kuth (@mpkuth) for rightfully pointed out that the __init__.py-less tests folder is likely common. I have also appended more test findings into my previous message above.
The tests will be removed from msal-extensions' next release, coming soon.
Activity
[-]`tests` are shipped as. module with the package[/-][+]`tests` are shipped as a module with the package[/+]fpgmaas commentedon Mar 14, 2025
Opened a PR that I think should fix this here.
rayluo commentedon Mar 14, 2025
Thanks for the catch. I intend to merge your PR #139 for cleaning purpose, if nothing else.
Out of curiosity, how bad is it for the shipped MSAL EX 1.3.0, though? Do we have to ship this fix quick? What actual issue did you run into, Florian Maas (@fpgmaas) , Michael Kuth (@mpkuth)? I did some quick tests, and it seems a project can still pick up their own
testsfolder.UPDATE:
The example in my tests above used a
testsfolder with a__init__.pyfile, and the import was able to locate it first, regardless of whether a packagetestsexists in site-packages. But if I remove that__init__.pyfile, the import indeed hits the packagetestsexists in site-packages. This subtleimportbehavior difference is likely the root cause.Michael Kuth (@mpkuth) rightfully pointed out that the
__init__.py-less tests folder is likely common.In any case, the
testswill be removed from msal-extensions' next release, coming soon.fpgmaas commentedon Mar 14, 2025
Ray Luo (@rayluo) For some of my projects it breaks the CI/CD pipelines. I created a small reproducible example here. The unit tests succeed without
msal-extensions, but they fail whenmsal-extensionsis added as a dependency.There are some workarounds of course;
msal-extensionsto1.2.0since the latest version ofazure-identitydepends on>=1.2.0tests.utilstotest_utils.So it is not very urgent, but I still think a
1.3.1release would be nice to release quickly in this case to prevent users of the package from having to modify their projects.mpkuth commentedon Mar 14, 2025
We use the same structure as the example provided by Florian Maas (@fpgmaas). The update caused
pytestto fail withEventually we tracked down the wayward
testsfolder insite-packagesto this package based on its contents.We worked around it by adding
__init__.pyto ourtestsfolder and changing the importsThe layout we use is suggested in the
pytestdocs, so I think this change has the potential to affect a lot of folks.https://docs.pytest.org/en/latest/explanation/goodpractices.html#tests-outside-application-code
rayluo commentedon Mar 14, 2025
Thanks Florian Maas (@fpgmaas) for going extra mile to set up a repo for repro. And thanks Michael Kuth (@mpkuth) for rightfully pointed out that the
__init__.py-less tests folder is likely common. I have also appended more test findings into my previous message above.The
testswill be removed from msal-extensions' next release, coming soon.rayluo commentedon Mar 14, 2025
Version 1.3.1 is shipped.