Repository: pytest-dev/pytest
File: testing/test_config.py (Python)

Code before:
        )
        config = pytester.parseconfig()
        # Canonical name should take precedence.
        assert config.getini("new_name") == "from_canonical"
        assert config.getini("old_name") == "from_canonical"

    def test_addini_aliases_multiple(self, pytester: Pytester) -> None:
        """Test that ini option can have multiple aliases."""
        pytester.makeconftest(
            """
            def pytest_addoption(parser):
                parser.addini("current_name", "my option", aliases=["old_name", "legacy_name"])
            """
        )
        pytester.makeini(
            """
            [pytest]
            old_name = value1
            """
        )
        config = pytester.parseconfig()
        assert config.getini("current_name") == "value1"
        assert config.getini("old_name") == "value1"
        assert config.getini("legacy_name") == "value1"

    def test_addini_aliases_with_override(self, pytester: Pytester) -> None:
        """Test that aliases work with --override-ini."""
        pytester.makeconftest(
            """
            def pytest_addoption(parser):
                parser.addini("new_name", "my option", aliases=["old_name"])
            """
        )
        pytester.makeini(
            """
            [pytest]
            old_name = from_file
            """
        )
        # Override using alias.
        config = pytester.parseconfig("-o", "old_name=overridden")
        assert config.getini("new_name") == "overridden"
        assert config.getini("old_name") == "overridden"

        # Override using canonical name.
        config = pytester.parseconfig("-o", "new_name=overridden2")
        assert config.getini("new_name") == "overridden2"

    def test_addini_aliases_with_types(self, pytester: Pytester) -> None:
        """Test that aliases work with different types."""
        pytester.makeconftest(

Review comment (suggestion):
Perhaps worth adding a test where the ini file uses the new name, and the cmdline override uses the old name.

Code after:
            """
        )
        config = pytester.parseconfig()
        # Canonical name should take precedence.
        assert config.getini("new_name") == "from_canonical"
        assert config.getini("old_name") == "from_canonical"

    def test_addini_aliases_multiple(self, pytester: Pytester) -> None:
        """Test that ini option can have multiple aliases."""
        pytester.makeconftest(
            """
            def pytest_addoption(parser):
                parser.addini("current_name", "my option", aliases=["old_name", "legacy_name"])
            """
        )
        pytester.makeini(
            """
            [pytest]
            old_name = value1
            """
        )
        config = pytester.parseconfig()
        assert config.getini("current_name") == "value1"
        assert config.getini("old_name") == "value1"
        assert config.getini("legacy_name") == "value1"

    def test_addini_aliases_with_override_of_old(self, pytester: Pytester) -> None:
        """Test that aliases work with --override-ini -- ini sets old."""
        pytester.makeconftest(
            """
            def pytest_addoption(parser):
                parser.addini("new_name", "my option", aliases=["old_name"])
            """
        )
        pytester.makeini(
            """
            [pytest]
            old_name = from_file
            """
        )
        # Override using alias.
        config = pytester.parseconfig("-o", "old_name=overridden")
        assert config.getini("new_name") == "overridden"
        assert config.getini("old_name") == "overridden"

        # Override using canonical name.
        config = pytester.parseconfig("-o", "new_name=overridden2")
        assert config.getini("new_name") == "overridden2"

    def test_addini_aliases_with_override_of_new(self, pytester: Pytester) -> None:
        """Test that aliases work with --override-ini -- ini sets new."""