christianhelle / autofaker

Python library designed to minimize the setup/arrange phase of your unit tests
MIT License
6 stars 3 forks source link

Add support for using AutoFaker Decorators with pytest #3

Closed christianhelle closed 2 years ago

christianhelle commented 2 years ago

This resolves #2

The changes here add support for the @autodata, @fakedata, @autopandas, and @fakepandas in tests using pytest

The following syntax is now supported:

from autofaker import autodata, fakedata

@autodata(str)
def test_create_str_using_decorator(text):
    assert text is not None

@autodata()
def test_create_str_using_decorator_with_type(text: str):
    assert text is not None

@autodata(str, use_fake_data=True)
def test_create_str_using_decorator_with_fake_data(text):
    assert text is not None@autodata(str, use_fake_data=True)

@fakedata()
def test_create_str_using_decorator_with_type_with_fake_data(text: str):
    assert text is not None

You can also use classes and nested classes

from autofaker import autodata, fakedata

class SimpleClass:
    id = -1
    name = 'name'
    text = 'test'

@autodata(SimpleClass)
def test_create_simple_class_using_decorator_returns_not_none(instance):
    assert instance is not None

@autodata()
def test_create_simple_class_using_decorator_with_type_returns_not_none(instance: SimpleClass):
    assert instance is not None

class NestedClass:
    id = -1
    name = 'name'
    text = 'test'
    inner = SimpleClass()

class DoubleNestedClass:
    id = -1
    name = 'name'
    text = 'test'
    inner = NestedClass()

@autodata(NestedClass)
def test_create_nested_class_using_decorator_returns_not_none(instance):
    assert instance is not None

@autodata()
def test_create_nested_class_using_decorator_with_type_returns_not_none(instance: NestedClass):
    assert instance is not None
sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication