pythonpython-3.xcompatibilitypython-poetrytox

How to check compatible library version interval for my package in python?


I am developing a private python library and I am using other public libraries in it. I want to define an interval of compatible version for every public library that my custom library uses.

I already implemented tests that check if the library works fine. Just need to find a way to test my code in every combination of every public library.

I tried to use tox but it seems like I have to write every combination of libraries in the tox.ini file so that it can create environments with libraries whose versions are different. Is there an automated way to do that?

For example: My development environment has following libraries and it passes my tests.

I want to know if I can test for combinations of

in an automated way.


Solution

  • Thanks everyone who helped me in the comment section. As @sinoroc suggested, using nox solved my problem in a very intuitive way. Even though this is not a common practice, I am sharing the solution that I used for given example in the question in case if there is anyone who needs to test their project like me.

    Codes in the noxfile.py are given below.

    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")
    

    Parametrize decorator defines the versions that will be used. Since I used two different versions for two different libraries, there will be 4(2*2) test results acquired from different version combinations.

    Note: I have observed that nox uses python -m pip command to install the libraries. Therefore, if the public libraries that we test have common dependencies between them, there may be an override problem where given version of a library is overwritten while installing another. I could not find a solution for it but this is as precise as version testing can get.