Skip to content

Commit

Permalink
Reproduce bug with list initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Feb 22, 2025
1 parent 1d7b5e8 commit 89d4da3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/test_instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from dataclasses import dataclass, field
from typing import Dict

import pytest

from datafiles import Missing, datafile
from datafiles.utils import logbreak, write

Expand All @@ -17,6 +19,7 @@
class SampleWithDefaults:
foo: int = 1
bar: str = "a"
items: list[str] = field(default_factory=list)


@dataclass
Expand Down Expand Up @@ -64,19 +67,22 @@ def it_wins_when_no_init_values(expect):
expect(sample.foo) == 2
expect(sample.bar) == "b"

@pytest.mark.xfail(reason="https://github.com/jacebrowning/datafiles/issues/344")
def it_loses_against_init_values(expect):
write(
"tmp/sample.yml",
"""
foo: 3
bar: c
items: ["aaa"]
""",
)

sample = SampleWithDefaults(4, "d")
sample = SampleWithDefaults(4, "d", ["aaa", "bbb"])

expect(sample.foo) == 4
expect(sample.bar) == "d"
expect(sample.items) == ["aaa", "bbb"]

def it_wins_against_default_init_values(expect):
write(
Expand Down

0 comments on commit 89d4da3

Please sign in to comment.