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
Before proceeding, please make sure to follow these steps:
[ x] I have checked for similar questions in the project's issue tracker to avoid duplicates.
[ x] I have searched existing issues to see if this question has been asked before.
Your Question
Is there a way to call license check from withing a pytest test-case in a github action?
I run tests as follows: uv run --frozen pytest tests/test_my_api.py
And run licensecheck as follows: licensecheck --ignore-packages package-without-license --ignore-license mpl --only-licenses mit bsd apache python --zero
I would like to call licensecheck from inside a unit test with parameters to skip certain package, ignore mpl licenses and allow only for mit/bsd/apacke and python.
Thanks!
The text was updated successfully, but these errors were encountered:
Thanks for raising this issue! The request to invoke licensecheck from within a pytest test case is an interesting use case, but it diverges somewhat from the original intent of this package. This tool was designed primarily to run in CI/CD pipelines or as part of pre-commit hooks, acting as a lightweight compliance check rather than a utility tightly coupled with unit tests.
That said, if you wish to call licensecheck programmatically within a pytest test case, it should be possible by leveraging Python's subprocess module. Or possibly by importing the library depending on what functionality you need. The tests in this repo may provide a good starting point
I have a task.py file, which I use as a task runner, which does precisely this thing (sort of). The only code you would need inside of pytest would be:
deftest_check_licenses():
importsubprocessassertsubprocess.run("licensecheck -0 <whatever other args>".split(sep=" ")) ==0
However, this couples the tests for your code for analyzers ran on your code, and this sort of thing is best handled by something like tox, which is meant to run things on your code/project for validation in CI/CD (including running your tests). This has the added benefit of being able to view the output of the code and keep it logged in your CI/CD environment. Tox has the added benefit of managing its own virtual environment so as to make it more consistent. The reason why I have a task runner on top of this is that tox can take a minute to set up, and sometimes you just want to run your validations quickly.
Before You Begin
Before proceeding, please make sure to follow these steps:
Your Question
Is there a way to call license check from withing a pytest test-case in a github action?
uv run --frozen pytest tests/test_my_api.py
licensecheck --ignore-packages package-without-license --ignore-license mpl --only-licenses mit bsd apache python --zero
I would like to call licensecheck from inside a unit test with parameters to skip certain package, ignore mpl licenses and allow only for mit/bsd/apacke and python.
Thanks!
The text was updated successfully, but these errors were encountered: