diff --git a/faker/utils/distribution.py b/faker/utils/distribution.py index 64cc2e084d..93b133d48f 100644 --- a/faker/utils/distribution.py +++ b/faker/utils/distribution.py @@ -61,7 +61,7 @@ def choices_distribution( if hasattr(random, 'choices'): if length == 1 and p is None: - return (random.choice(a),) + return [random.choice(a)] else: return random.choices(a, weights=p, k=length) else: diff --git a/tests/providers/__init__.py b/tests/providers/__init__.py index 23816985dd..d175f3a255 100644 --- a/tests/providers/__init__.py +++ b/tests/providers/__init__.py @@ -152,6 +152,11 @@ def test_random_letter(self, faker, num_samples): letter = faker.random_letter() assert letter.isalpha() + def test_random_letters(self, faker): + assert isinstance(faker.random_letters(length=0), list) + assert isinstance(faker.random_letters(length=1), list) + assert isinstance(faker.random_letters(length=2), list) + def test_random_lowercase_letter(self, faker, num_samples): for _ in range(num_samples): letter = faker.random_lowercase_letter()