0

私のテストでは、コマンドを実行して、仮想環境にインストールされているパッケージが にあるパッケージと一致することを確認したいと考えていますPipfile.lock

このようなコマンドはありますか?

pipenv checkifinstalled || exit 1
4

1 に答える 1

0

This problem can be reduced down to these two steps:

  1. Convert Pipfile.lock into a requirements.txt file (in the format generated by pip freeze).

    • This is easily done by running pipenv lock -r (or pipenv lock -r --dev)
  2. Check that the installed packages match the generated requirements.txt file.

Implementation:

Here is how I put it all together in a test:

import pkg_resources
import subprocess
import unittest

class DependencyChecks(unittest.TestCase):
    def test_requirements_installed(self):
        requirements_lines = subprocess.check_output(["pipenv", "lock", "-r", "--dev"], text=True).splitlines()
        req_lines = [line for line in requirements_lines if not line.startswith("-i ")]
        requirements = pkg_resources.parse_requirements(req_lines)
        for requirement in requirements:
            req = str(requirement)
            with self.subTest(requirement=req):
                pkg_resources.require(req)
于 2022-02-11T13:17:43.847 に答える