Python:如果我的软件包在Linux,Mac和Windows上运行,我如何测试它

时间:2022-12-27 17:40:17

I need to test my Python package if it works properly on different systems. I found Tox for different Python versions, but what about different operating systems like Windows, Linux and Mac.

如果它在不同的系统上正常工作,我需要测试我的Python包。我发现Tox适用于不同的Python版本,但是不同的操作系统如Windows,Linux和Mac。

Can you recommend me a convenient way to test if my code works on all systems?

您能否为我推荐一种方便的方法来测试我的代码是否适用于所有系统?

1 个解决方案

#1


1  

You'll need (possibly virtual) machines running one of each operating system. Personally, I just run my unit tests on different physical machines, but nearly all of my code is operating-system independent, so I can do most of my development on one operating system during the day and just run the tests on the other OSes at the end of the day.

您需要(可能是虚拟的)机器运行每个操作系统之一。就个人而言,我只是在不同的物理机器上运行我的单元测试,但几乎所有的代码都是独立于操作系统的,因此我可以在一天内在一个操作系统上进行大部分开发,只需在其他操作系统上运行测试一天结束。

If you have operating-system dependent code (e.g., Windows handles the Python multiprocessing package differently from Unix), you can use the unittest module's skip functionality to skip tests of, say, Windows behavior when you're running the tests on Mac OS.

如果您具有依赖于操作系统的代码(例如,Windows处理Python多处理程序包与Unix不同),则可以使用unittest模块的跳过功能,以便在Mac OS上运行测试时跳过Windows行为的测试。

#1


1  

You'll need (possibly virtual) machines running one of each operating system. Personally, I just run my unit tests on different physical machines, but nearly all of my code is operating-system independent, so I can do most of my development on one operating system during the day and just run the tests on the other OSes at the end of the day.

您需要(可能是虚拟的)机器运行每个操作系统之一。就个人而言,我只是在不同的物理机器上运行我的单元测试,但几乎所有的代码都是独立于操作系统的,因此我可以在一天内在一个操作系统上进行大部分开发,只需在其他操作系统上运行测试一天结束。

If you have operating-system dependent code (e.g., Windows handles the Python multiprocessing package differently from Unix), you can use the unittest module's skip functionality to skip tests of, say, Windows behavior when you're running the tests on Mac OS.

如果您具有依赖于操作系统的代码(例如,Windows处理Python多处理程序包与Unix不同),则可以使用unittest模块的跳过功能,以便在Mac OS上运行测试时跳过Windows行为的测试。