Home  >  Article  >  Backend Development  >  How do I check my package's compatibility library version interval in python?

How do I check my package's compatibility library version interval in python?

WBOY
WBOYforward
2024-02-08 22:21:241143browse

如何在 python 中检查我的包的兼容库版本间隔?

Question content

I am developing a private Python library and I am using other public libraries in it. I want to define a compatible version interval for each public library my custom library uses.

I have implemented tests to check if the library is working properly. Just need to find a way to test my code in every combination of every public library.

I tried using tox, but it seems I have to write a combination of each library in the tox.ini file so that it can create the environment with different versions of the libraries. Is there an automated way to do this?

For example: My development environment has the following libraries, and they passed my tests.

  • numpy==1.24.3

  • matplotlib==3.7.3

I would like to know if it is possible to test the following combination

  • numpy==1.24.0, 1.24.1 ... 1.24.x
  • matplotlib==3.7.1, 3.7.2 ... 3.7.x

In an automated manner.


Correct answer


Thanks to everyone who helped me in the comment section. As @sinoroc suggested, using nox solved my problem in a very intuitive way. Although this isn't common practice, I'll share the solution I used in the example given in the question in case someone like me needs to test their project.

The code in

noxfile.py is as follows.

import nox

@nox.session(name = "test_sample")
@nox.parametrize("numpy", ["1.24.3", "1.24.2"])
@nox.parametrize("matplotlib", ["3.7.3", "3.7.2"])
def tests(session, numpy, matplotlib):
    session.install(f"numpy=={numpy}", f"matplotlib=={matplotlib}")
    session.run("pytest")

Parameterized decorator defines the version that will be used. Since I used two different versions of two different libraries, I would get 4 (2*2) test results for different combinations of versions.

Note: I observed that nox uses the python -m pip command to install libraries. Therefore, if there are common dependencies between the public libraries we test, coverage issues may arise where a given version of the library is overwritten when another library is installed. I can't find a solution, but this is as accurate as version testing can get.

The above is the detailed content of How do I check my package's compatibility library version interval in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete