简体   繁体   English

如何为我的 package 测试 setup.py?

[英]How do I test the setup.py for my package?

I have a pretty big Python package I've written, about 3500 statements, with a robust unit and acceptance test suite.我有一个相当大的 Python package 我写了大约 3500 条语句,有一个健壮的单元和验收测试套件。 I feel quite confident about the quality of the code itself, but I'm uneasy about the install process going smoothly for users of the package as I don't know how to reliably test the install in an appropriately isolated environment, short of something like keeping a spare machine around and re-imaging it with a fresh OS install for each test run.我对代码本身的质量很有信心,但我对 package 用户的安装过程顺利进行感到不安,因为我不知道如何在适当隔离的环境中可靠地测试安装,缺少类似的东西保留一台备用机器,并在每次测试运行时使用全新的操作系统安装对其进行重新映像。

I suspect using virtualenv in the right way might provide a proper test fixture for testing installation, but after extended web searches have uncovered no helpful guidance.我怀疑以正确的方式使用 virtualenv 可能会为测试安装提供适当的测试装置,但在扩展 web 搜索后没有发现任何有用的指导。

How can I effectively test my setup.py and other installation bits on my development machine?如何在我的开发机器上有效地测试我的 setup.py 和其他安装位?

If you like tools ( which I do ) check out fabric and the set of Fabric tasks I've written across all my projects: 如果您喜欢工具( 我愿意 ),请签出Fabric和我在所有项目中编写的Fabric任务集:

eg: circuits' fabfile 例如: 电路的fabfile

This should work for just about any Python project and utilizes: 这应该适用于几乎所有Python项目并利用:

  • Sphinx 狮身人面像
  • py.test/tox py.test / tox
  • virtualenv 虚拟环境

Some basic workflows: 一些基本的工作流程:

fab build    # build the package in non-development mode
fab develop  # build the package in development mode
fab docs     # build/regenerate the documentation
fab test     # run tie unit test suite
fab release  # run through a tested release cycle

Type: fab -l for a list of commands and fab help:<name> for help on any command. 键入: fab -l获取命令列表和fab help:<name>获取有关任何命令的帮助。

Update: Recently we added fab docker commands to work with Docker 更新:最近我们添加了fab docker命令以与Docker一起使用

fab docker:build    # Build a Docker image
fab docker:publish  # Publish Docker image to the Docker Hub
fab docker:run      # Run a new Docker container

If you really want isolation instead just doing python setup.py install in virtualenv. 如果您真的想要隔离,则只需在virtualenv中python setup.py install Then use virtualbox and install some free linux os in it. 然后使用virtualbox并在其中安装一些免费的Linux操作系统。 Take a snapshot of the machine after the install so you can revert easily with one click to the starting point at any time and try python setup.py install there. 安装后为计算机拍摄快照,以便您随时可以轻松地一键还原到起点,然后尝试在此处python setup.py install

I think basic tox config does this job automatically.我认为基本的tox配置会自动完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM