|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +@pytest.mark.install |
| 5 | +@pytest.mark.uninstall |
| 6 | +def test_uninstall_dev_flag(pipenv_instance_private_pypi): |
| 7 | + """Ensure that running `pipenv uninstall --dev` properly removes packages from dev-packages""" |
| 8 | + with pipenv_instance_private_pypi() as p: |
| 9 | + with open(p.pipfile_path, "w") as f: |
| 10 | + contents = """ |
| 11 | +[packages] |
| 12 | +six = "*" |
| 13 | +
|
| 14 | +[dev-packages] |
| 15 | +pytest = "*" |
| 16 | + """.strip() |
| 17 | + f.write(contents) |
| 18 | + |
| 19 | + # Install both packages |
| 20 | + c = p.pipenv("install --dev") |
| 21 | + assert c.returncode == 0 |
| 22 | + assert "six" in p.pipfile["packages"] |
| 23 | + assert "pytest" in p.pipfile["dev-packages"] |
| 24 | + assert "six" in p.lockfile["default"] |
| 25 | + assert "pytest" in p.lockfile["develop"] |
| 26 | + |
| 27 | + # Verify both packages are installed |
| 28 | + c = p.pipenv('run python -c "import six, pytest"') |
| 29 | + assert c.returncode == 0 |
| 30 | + |
| 31 | + # Uninstall pytest with --dev flag |
| 32 | + c = p.pipenv("uninstall pytest --dev") |
| 33 | + assert c.returncode == 0 |
| 34 | + |
| 35 | + # Verify pytest was removed from dev-packages |
| 36 | + assert "six" in p.pipfile["packages"] |
| 37 | + assert "pytest" not in p.pipfile["dev-packages"] |
| 38 | + assert "six" in p.lockfile["default"] |
| 39 | + assert "pytest" not in p.lockfile["develop"] |
| 40 | + |
| 41 | + # Verify pytest is no longer importable |
| 42 | + c = p.pipenv('run python -c "import pytest"') |
| 43 | + assert c.returncode != 0 |
| 44 | + |
| 45 | + # Verify six is still importable |
| 46 | + c = p.pipenv('run python -c "import six"') |
| 47 | + assert c.returncode == 0 |
| 48 | + |
| 49 | + |
| 50 | +@pytest.mark.install |
| 51 | +@pytest.mark.uninstall |
| 52 | +def test_uninstall_dev_flag_with_categories(pipenv_instance_private_pypi): |
| 53 | + """Ensure that running `pipenv uninstall --dev` works the same as `--categories dev-packages`""" |
| 54 | + with pipenv_instance_private_pypi() as p: |
| 55 | + with open(p.pipfile_path, "w") as f: |
| 56 | + contents = """ |
| 57 | +[packages] |
| 58 | +six = "*" |
| 59 | +
|
| 60 | +[dev-packages] |
| 61 | +pytest = "*" |
| 62 | + """.strip() |
| 63 | + f.write(contents) |
| 64 | + |
| 65 | + # Install both packages |
| 66 | + c = p.pipenv("install --dev") |
| 67 | + assert c.returncode == 0 |
| 68 | + |
| 69 | + # Create a second project to test with categories |
| 70 | + with pipenv_instance_private_pypi() as p2: |
| 71 | + with open(p2.pipfile_path, "w") as f: |
| 72 | + contents = """ |
| 73 | +[packages] |
| 74 | +six = "*" |
| 75 | +
|
| 76 | +[dev-packages] |
| 77 | +pytest = "*" |
| 78 | + """.strip() |
| 79 | + f.write(contents) |
| 80 | + |
| 81 | + # Install both packages |
| 82 | + c = p2.pipenv("install --dev") |
| 83 | + assert c.returncode == 0 |
| 84 | + |
| 85 | + # Uninstall pytest with --categories |
| 86 | + c = p2.pipenv("uninstall pytest --categories dev-packages") |
| 87 | + assert c.returncode == 0 |
| 88 | + |
| 89 | + # Verify pytest was removed from dev-packages |
| 90 | + assert "six" in p2.pipfile["packages"] |
| 91 | + assert "pytest" not in p2.pipfile["dev-packages"] |
| 92 | + assert "six" in p2.lockfile["default"] |
| 93 | + assert "pytest" not in p2.lockfile["develop"] |
| 94 | + |
| 95 | + # Compare with first project |
| 96 | + c = p.pipenv("uninstall pytest --dev") |
| 97 | + assert c.returncode == 0 |
| 98 | + |
| 99 | + # Verify both approaches have the same result |
| 100 | + assert p.pipfile["packages"] == p2.pipfile["packages"] |
| 101 | + assert p.pipfile["dev-packages"] == p2.pipfile["dev-packages"] |
| 102 | + assert p.lockfile["default"] == p2.lockfile["default"] |
| 103 | + assert p.lockfile["develop"] == p2.lockfile["develop"] |
0 commit comments