Skip to content

Commit c3daf91

Browse files
martin056RadoRado
authored andcommitted
Add comments for better understaging of the code
1 parent 37fbc26 commit c3daf91

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

styleguide_example/test_examples/tests/factories.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,17 @@ class Meta:
6363
SchoolCourseFactory,
6464
school=factory.SelfAttribute('..student.school')
6565
)
66+
# The `SelfAttribute` is just an interface that uses LazyAttribute under the hood:
67+
# school_course = factory.SubFactory(
68+
# SchoolCourseFactory,
69+
# school=factory.LazyAttribute(lambda course: course.factory_parent.student.school)
70+
# )
6671

6772
start_date = factory.SelfAttribute('school_course.start_date')
6873
end_date = factory.SelfAttribute('school_course.end_date')
6974

7075
active = True
76+
# We'd recommend you using LazyAttribute instead of Maybe as it's more explicit
7177
deactivated_at = factory.Maybe(
7278
'active',
7379
no_declaration=factory.LazyAttribute(lambda self: faker.date_between_dates(
@@ -86,6 +92,12 @@ def get_future_roster_start_date(roster_obj):
8692

8793

8894
class FutureRosterFactory(RosterFactory):
95+
"""
96+
Example usage:
97+
future_roster1 = FutureRosterFactory()
98+
future_roster2 = FutureRosterFactory(start_after=future_roster1.end_date)
99+
"""
100+
89101
class Params:
90102
start_after = None
91103

0 commit comments

Comments
 (0)