diff --git a/PyCon_PL/Readme.md b/PyCon_PL/Readme.md index 6618ce4..ee664be 100644 --- a/PyCon_PL/Readme.md +++ b/PyCon_PL/Readme.md @@ -1,3 +1,4 @@ 1. [Grzegorz Kocjan - Test Driven Pandas](https://youtu.be/oaADte_9u6Q) - [Folder](./Test_Driven_Pandas/) - - [Link](https://belazy.dev/talks/test-driven-pandas/) \ No newline at end of file + - [Link](https://belazy.dev/talks/test-driven-pandas/) + - [Pytest Fixture Ref](https://twpower.github.io/19-about-python-test-fixture) \ No newline at end of file diff --git a/PyCon_PL/Test_Driven_Pandas/tests/test_gradebook.py b/PyCon_PL/Test_Driven_Pandas/tests/test_gradebook.py index 268b61f..b73ea13 100644 --- a/PyCon_PL/Test_Driven_Pandas/tests/test_gradebook.py +++ b/PyCon_PL/Test_Driven_Pandas/tests/test_gradebook.py @@ -1,4 +1,5 @@ import pandas as pd +import pytest from typing import cast def _create_group(raw_students_group:pd.DataFrame) -> pd.DataFrame: @@ -45,8 +46,8 @@ def test_results_are_grouped_by_student_group_for_students_in_multiple_group(): result = generate_gradebook(students_df=students_df) assert list(result.keys()) == [1, 2] - -def test_results_group_contains_students_net_id_lowercase(): +@pytest.fixture +def two_students_in_the_same_group() -> pd.DataFrame(): students = [ { "ID": 1, @@ -63,32 +64,17 @@ def test_results_group_contains_students_net_id_lowercase(): "Group": 1, }, ] - students_df = pd.DataFrame(data=students).set_index("ID") + return pd.DataFrame(data=students).set_index("ID") - result = generate_gradebook(students_df=students_df) +def test_results_group_contains_students_net_id_lowercase(two_students_in_the_same_group): + + result = generate_gradebook(students_df=two_students_in_the_same_group) assert result[1]["net_id"].to_list() == ["jxd12345", "sxd54321"] -def test_results_group_contains_students_email_address_lowercase(): - students = [ - { - "ID": 1, - "Name": "Doe, John", - "NetID": "JXD12345", - "Email Address": "JOHN.DOE@EXAMPLE.EDU", - "Group": 1, - }, - { - "ID": 2, - "Name": "Doe, Second", - "NetID": "SXD54321", - "Email Address": "SECOND.DOE@EXAMPLE.EDU", - "Group": 1, - }, - ] - students_df = pd.DataFrame(data=students).set_index("ID") +def test_results_group_contains_students_email_address_lowercase(two_students_in_the_same_group): - result = generate_gradebook(students_df = students_df) + result = generate_gradebook(students_df = two_students_in_the_same_group) assert result[1]['email_address'].to_list() == [ 'john.doe@example.edu',