diff --git a/poetry/packages/package.py b/poetry/packages/package.py index 8e47ddc952c..5b7dfea09d1 100644 --- a/poetry/packages/package.py +++ b/poetry/packages/package.py @@ -297,6 +297,7 @@ def add_dependency( branch=constraint.get("branch", None), tag=constraint.get("tag", None), rev=constraint.get("rev", None), + category=category, optional=optional, ) elif "file" in constraint: diff --git a/poetry/packages/vcs_dependency.py b/poetry/packages/vcs_dependency.py index e02b33107d2..eadd73fa111 100644 --- a/poetry/packages/vcs_dependency.py +++ b/poetry/packages/vcs_dependency.py @@ -7,7 +7,15 @@ class VCSDependency(Dependency): """ def __init__( - self, name, vcs, source, branch=None, tag=None, rev=None, optional=False + self, + name, + vcs, + source, + branch=None, + tag=None, + rev=None, + category="main", + optional=False, ): self._vcs = vcs self._source = source @@ -21,7 +29,7 @@ def __init__( self._rev = rev super(VCSDependency, self).__init__( - name, "*", optional=optional, allows_prereleases=True + name, "*", category=category, optional=optional, allows_prereleases=True ) @property diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py index 61e9060af52..b61de86e540 100644 --- a/tests/packages/test_package.py +++ b/tests/packages/test_package.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import pytest + from poetry.packages import Package @@ -14,3 +16,24 @@ def test_package_authors(): package.authors.insert(0, "John Doe") assert package.author_name == "John Doe" assert package.author_email is None + + +@pytest.mark.parametrize("category", ["main", "dev"]) +def test_package_add_dependency_vcs_category(category): + package = Package("foo", "0.1.0") + + dependency = package.add_dependency( + "poetry", + constraint={"git": "https://github.com/python-poetry/poetry.git"}, + category=category, + ) + assert dependency.category == category + + +def test_package_add_dependency_vcs_category_default_main(): + package = Package("foo", "0.1.0") + + dependency = package.add_dependency( + "poetry", constraint={"git": "https://github.com/python-poetry/poetry.git"} + ) + assert dependency.category == "main" diff --git a/tests/packages/test_vcs_dependency.py b/tests/packages/test_vcs_dependency.py index 767a706212d..18ff9d81e9a 100644 --- a/tests/packages/test_vcs_dependency.py +++ b/tests/packages/test_vcs_dependency.py @@ -1,3 +1,5 @@ +import pytest + from poetry.packages.vcs_dependency import VCSDependency @@ -49,3 +51,14 @@ def test_to_pep_508_in_extras(): expected = 'poetry @ git+https://github.com/python-poetry/poetry.git@b;ar; ; extra == "foo;"' assert expected == dependency.to_pep_508() + + +@pytest.mark.parametrize("category", ["main", "dev"]) +def test_category(category): + dependency = VCSDependency( + "poetry", + "git", + "https://github.com/python-poetry/poetry.git", + category=category, + ) + assert category == dependency.category