We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Use setUpTestData in tests 
`setUp` is ran before every test method but `setUpTestData` is run only once for the whole test class. Each test method is run in a transaction and rolled back at the end, so there is no need to re-create the database data for each method separately. Most of the time in unit tests seems to be spent on creating data for the tests, so it would be a massive speed up to reuse the data by using `setUpTestData`.

`setUpTestData` takes the class as an argument but it can be used similarly to `setUp`: just assign the properties to the class (e.g. `cls.instance = CourseInstance...`) and the property can be accessed normally through the object (e.g. `self.instance`).

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/testdata.py`
Content:
```
1 from datetime import timedelta
2 from django.conf import settings
3 from django.contrib.auth.models import User
4 from django.test import TestCase
5 from django.utils import timezone
6 
7 from course.models import (
8     Course,
9     CourseInstance,
10     CourseModule,
11     LearningObjectCategory,
12 )
13 from exercise.models import (
14     BaseExercise,
15     StaticExercise,
16     Submission,
17 )
18 
19 
20 class CourseTestCase(TestCase):
21 
22     def setUp(self):
23         self.setUpCourse()
24         self.setUpSubmissions()
25 
26     def setUpCourse(self):
27 
28         self.now = timezone.now()
29         self.tomorrow = self.now + timedelta(days=1)
30         self.two_days_after = self.now + timedelta(days=2)
31         self.three_days_after = self.now + timedelta(days=3)
32         self.yesterday = self.now - timedelta(days=1)
33         self.two_days_before = self.now - timedelta(days=2)
34 
35         self.user = User(username='testUser')
36         self.user.set_password('testPassword')
37         self.user.save()
38 
39         self.teacher = User(username='testTeacher')
40         self.teacher.set_password('testPassword')
41         self.teacher.save()
42 
43         self.student = User(username='testStudent')
44         self.student.set_password('testPassword')
45         self.student.save()
46         self.student.userprofile.student_id = "123TEST"
47         self.student.userprofile.organization = settings.LOCAL_ORGANIZATION
48         self.student.userprofile.save()
49 
50         self.course = Course.objects.create(
51             url="course",
52             name="Test Course",
53             code="123456",
54         )
55 
56         self.instance = CourseInstance.objects.create(
57             course=self.course,
58             url="instance",
59             instance_name="2016",
60             starting_time=self.now,
61             ending_time=self.tomorrow,
62         )
63         self.instance.add_teacher(self.teacher.userprofile)
64         self.instance.enroll_student(self.student)
65 
66         self.module = CourseModule.objects.create(
67             course_instance=self.instance,
68             url="module",
69             name="Test Module",
70             points_to_pass=10,
71             opening_time=self.now,
72             closing_time=self.tomorrow,
73             late_submissions_allowed=True,
74             late_submission_deadline=self.two_days_after,
75             late_submission_penalty=0.2
76         )
77         self.module2 = CourseModule.objects.create(
78             course_instance=self.instance,
79             url="module2",
80             name="Test Module 2",
81             points_to_pass=0,
82             opening_time=self.tomorrow,
83             closing_time=self.two_days_after,
84         )
85         self.module0 = CourseModule.objects.create(
86             course_instance=self.instance,
87             url="module0",
88             name="Past Module",
89             points_to_pass=10,
90             opening_time=self.two_days_before,
91             closing_time=self.yesterday,
92         )
93         self.category = LearningObjectCategory.objects.create(
94             course_instance=self.instance,
95             name="Test Category",
96             points_to_pass=5,
97         )
98 
99         self.exercise = StaticExercise.objects.create(
100             course_module=self.module,
101             category=self.category,
102             url='e1',
103             name="Test Exercise",
104             exercise_page_content='$$exercise$$content',
105             submission_page_content='$$exercise$$received',
106             points_to_pass=0,
107             max_points=100,
108             order=1,
109         )
110         self.exercise2 = StaticExercise.objects.create(
111             course_module=self.module,
112             category=self.category,
113             url='e2',
114             name="Test Exercise 2",
115             exercise_page_content='$$exercise2$$content',
116             submission_page_content='$$exercise2$$received',
117             points_to_pass=10,
118             max_points=100,
119             order=2,
120         )
121         self.exercise3 = StaticExercise.objects.create(
122             course_module=self.module2,
123             category=self.category,
124             url='e3',
125             name="Test Exercise 3",
126             exercise_page_content='$$exercise3$$content',
127             submission_page_content='$$exercise3$$received',
128             points_to_pass=0,
129             max_points=100,
130         )
131         self.exercise0 = BaseExercise.objects.create(
132             course_module=self.module0,
133             category=self.category,
134             url='b0',
135             name="Base Exercise 0",
136             service_url="http://localhost/",
137             points_to_pass=0,
138             max_points=100,
139             min_group_size=1,
140             max_group_size=2,
141         )
142 
143     def setUpSubmissions(self):
144 
145         self.submission = Submission.objects.create(
146             exercise=self.exercise,
147             submission_data={'submission':1},
148             feedback='$$submission$$feedback',
149         )
150         self.submission.submitters.add(self.student.userprofile)
151         self.submission.set_points(1,2)
152         self.submission.set_ready()
153         self.submission.save()
154 
155         self.submission2 = Submission.objects.create(
156             exercise=self.exercise,
157             submission_data={'submission':2},
158         )
159         self.submission2.submitters.add(self.student.userprofile)
160 
161         self.submission3 = Submission.objects.create(
162             exercise=self.exercise2,
163             submission_data={'submission':3},
164         )
165         self.submission3.submitters.add(self.student.userprofile)
166         self.submission3.submitters.add(self.user.userprofile)
167
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lib/testdata.py b/lib/testdata.py
--- a/lib/testdata.py
+++ b/lib/testdata.py
@@ -19,10 +19,12 @@
 
 class CourseTestCase(TestCase):
 
-    def setUp(self):
-        self.setUpCourse()
-        self.setUpSubmissions()
+    @classmethod
+    def setUpTestData(cls):
+        cls.setUpCourse()
+        cls.setUpSubmissions()
 
+    @classmethod
     def setUpCourse(self):
 
         self.now = timezone.now()
@@ -140,6 +142,7 @@
             max_group_size=2,
         )
 
+    @classmethod
     def setUpSubmissions(self):
 
         self.submission = Submission.objects.create(

{"golden_diff": "diff --git a/lib/testdata.py b/lib/testdata.py\n--- a/lib/testdata.py\n+++ b/lib/testdata.py\n@@ -19,10 +19,12 @@\n \n class CourseTestCase(TestCase):\n \n-    def setUp(self):\n-        self.setUpCourse()\n-        self.setUpSubmissions()\n+    @classmethod\n+    def setUpTestData(cls):\n+        cls.setUpCourse()\n+        cls.setUpSubmissions()\n \n+    @classmethod\n     def setUpCourse(self):\n \n         self.now = timezone.now()\n@@ -140,6 +142,7 @@\n             max_group_size=2,\n         )\n \n+    @classmethod\n     def setUpSubmissions(self):\n \n         self.submission = Submission.objects.create(\n", "issue": "Use setUpTestData in tests \n`setUp` is ran before every test method but `setUpTestData` is run only once for the whole test class. Each test method is run in a transaction and rolled back at the end, so there is no need to re-create the database data for each method separately. Most of the time in unit tests seems to be spent on creating data for the tests, so it would be a massive speed up to reuse the data by using `setUpTestData`.\r\n\r\n`setUpTestData` takes the class as an argument but it can be used similarly to `setUp`: just assign the properties to the class (e.g. `cls.instance = CourseInstance...`) and the property can be accessed normally through the object (e.g. `self.instance`).\n", "before_files": [{"content": "from datetime import timedelta\nfrom django.conf import settings\nfrom django.contrib.auth.models import User\nfrom django.test import TestCase\nfrom django.utils import timezone\n\nfrom course.models import (\n    Course,\n    CourseInstance,\n    CourseModule,\n    LearningObjectCategory,\n)\nfrom exercise.models import (\n    BaseExercise,\n    StaticExercise,\n    Submission,\n)\n\n\nclass CourseTestCase(TestCase):\n\n    def setUp(self):\n        self.setUpCourse()\n        self.setUpSubmissions()\n\n    def setUpCourse(self):\n\n        self.now = timezone.now()\n        self.tomorrow = self.now + timedelta(days=1)\n        self.two_days_after = self.now + timedelta(days=2)\n        self.three_days_after = self.now + timedelta(days=3)\n        self.yesterday = self.now - timedelta(days=1)\n        self.two_days_before = self.now - timedelta(days=2)\n\n        self.user = User(username='testUser')\n        self.user.set_password('testPassword')\n        self.user.save()\n\n        self.teacher = User(username='testTeacher')\n        self.teacher.set_password('testPassword')\n        self.teacher.save()\n\n        self.student = User(username='testStudent')\n        self.student.set_password('testPassword')\n        self.student.save()\n        self.student.userprofile.student_id = \"123TEST\"\n        self.student.userprofile.organization = settings.LOCAL_ORGANIZATION\n        self.student.userprofile.save()\n\n        self.course = Course.objects.create(\n            url=\"course\",\n            name=\"Test Course\",\n            code=\"123456\",\n        )\n\n        self.instance = CourseInstance.objects.create(\n            course=self.course,\n            url=\"instance\",\n            instance_name=\"2016\",\n            starting_time=self.now,\n            ending_time=self.tomorrow,\n        )\n        self.instance.add_teacher(self.teacher.userprofile)\n        self.instance.enroll_student(self.student)\n\n        self.module = CourseModule.objects.create(\n            course_instance=self.instance,\n            url=\"module\",\n            name=\"Test Module\",\n            points_to_pass=10,\n            opening_time=self.now,\n            closing_time=self.tomorrow,\n            late_submissions_allowed=True,\n            late_submission_deadline=self.two_days_after,\n            late_submission_penalty=0.2\n        )\n        self.module2 = CourseModule.objects.create(\n            course_instance=self.instance,\n            url=\"module2\",\n            name=\"Test Module 2\",\n            points_to_pass=0,\n            opening_time=self.tomorrow,\n            closing_time=self.two_days_after,\n        )\n        self.module0 = CourseModule.objects.create(\n            course_instance=self.instance,\n            url=\"module0\",\n            name=\"Past Module\",\n            points_to_pass=10,\n            opening_time=self.two_days_before,\n            closing_time=self.yesterday,\n        )\n        self.category = LearningObjectCategory.objects.create(\n            course_instance=self.instance,\n            name=\"Test Category\",\n            points_to_pass=5,\n        )\n\n        self.exercise = StaticExercise.objects.create(\n            course_module=self.module,\n            category=self.category,\n            url='e1',\n            name=\"Test Exercise\",\n            exercise_page_content='$$exercise$$content',\n            submission_page_content='$$exercise$$received',\n            points_to_pass=0,\n            max_points=100,\n            order=1,\n        )\n        self.exercise2 = StaticExercise.objects.create(\n            course_module=self.module,\n            category=self.category,\n            url='e2',\n            name=\"Test Exercise 2\",\n            exercise_page_content='$$exercise2$$content',\n            submission_page_content='$$exercise2$$received',\n            points_to_pass=10,\n            max_points=100,\n            order=2,\n        )\n        self.exercise3 = StaticExercise.objects.create(\n            course_module=self.module2,\n            category=self.category,\n            url='e3',\n            name=\"Test Exercise 3\",\n            exercise_page_content='$$exercise3$$content',\n            submission_page_content='$$exercise3$$received',\n            points_to_pass=0,\n            max_points=100,\n        )\n        self.exercise0 = BaseExercise.objects.create(\n            course_module=self.module0,\n            category=self.category,\n            url='b0',\n            name=\"Base Exercise 0\",\n            service_url=\"http://localhost/\",\n            points_to_pass=0,\n            max_points=100,\n            min_group_size=1,\n            max_group_size=2,\n        )\n\n    def setUpSubmissions(self):\n\n        self.submission = Submission.objects.create(\n            exercise=self.exercise,\n            submission_data={'submission':1},\n            feedback='$$submission$$feedback',\n        )\n        self.submission.submitters.add(self.student.userprofile)\n        self.submission.set_points(1,2)\n        self.submission.set_ready()\n        self.submission.save()\n\n        self.submission2 = Submission.objects.create(\n            exercise=self.exercise,\n            submission_data={'submission':2},\n        )\n        self.submission2.submitters.add(self.student.userprofile)\n\n        self.submission3 = Submission.objects.create(\n            exercise=self.exercise2,\n            submission_data={'submission':3},\n        )\n        self.submission3.submitters.add(self.student.userprofile)\n        self.submission3.submitters.add(self.user.userprofile)\n", "path": "lib/testdata.py"}], "after_files": [{"content": "from datetime import timedelta\nfrom django.conf import settings\nfrom django.contrib.auth.models import User\nfrom django.test import TestCase\nfrom django.utils import timezone\n\nfrom course.models import (\n    Course,\n    CourseInstance,\n    CourseModule,\n    LearningObjectCategory,\n)\nfrom exercise.models import (\n    BaseExercise,\n    StaticExercise,\n    Submission,\n)\n\n\nclass CourseTestCase(TestCase):\n\n    @classmethod\n    def setUpTestData(cls):\n        cls.setUpCourse()\n        cls.setUpSubmissions()\n\n    @classmethod\n    def setUpCourse(self):\n\n        self.now = timezone.now()\n        self.tomorrow = self.now + timedelta(days=1)\n        self.two_days_after = self.now + timedelta(days=2)\n        self.three_days_after = self.now + timedelta(days=3)\n        self.yesterday = self.now - timedelta(days=1)\n        self.two_days_before = self.now - timedelta(days=2)\n\n        self.user = User(username='testUser')\n        self.user.set_password('testPassword')\n        self.user.save()\n\n        self.teacher = User(username='testTeacher')\n        self.teacher.set_password('testPassword')\n        self.teacher.save()\n\n        self.student = User(username='testStudent')\n        self.student.set_password('testPassword')\n        self.student.save()\n        self.student.userprofile.student_id = \"123TEST\"\n        self.student.userprofile.organization = settings.LOCAL_ORGANIZATION\n        self.student.userprofile.save()\n\n        self.course = Course.objects.create(\n            url=\"course\",\n            name=\"Test Course\",\n            code=\"123456\",\n        )\n\n        self.instance = CourseInstance.objects.create(\n            course=self.course,\n            url=\"instance\",\n            instance_name=\"2016\",\n            starting_time=self.now,\n            ending_time=self.tomorrow,\n        )\n        self.instance.add_teacher(self.teacher.userprofile)\n        self.instance.enroll_student(self.student)\n\n        self.module = CourseModule.objects.create(\n            course_instance=self.instance,\n            url=\"module\",\n            name=\"Test Module\",\n            points_to_pass=10,\n            opening_time=self.now,\n            closing_time=self.tomorrow,\n            late_submissions_allowed=True,\n            late_submission_deadline=self.two_days_after,\n            late_submission_penalty=0.2\n        )\n        self.module2 = CourseModule.objects.create(\n            course_instance=self.instance,\n            url=\"module2\",\n            name=\"Test Module 2\",\n            points_to_pass=0,\n            opening_time=self.tomorrow,\n            closing_time=self.two_days_after,\n        )\n        self.module0 = CourseModule.objects.create(\n            course_instance=self.instance,\n            url=\"module0\",\n            name=\"Past Module\",\n            points_to_pass=10,\n            opening_time=self.two_days_before,\n            closing_time=self.yesterday,\n        )\n        self.category = LearningObjectCategory.objects.create(\n            course_instance=self.instance,\n            name=\"Test Category\",\n            points_to_pass=5,\n        )\n\n        self.exercise = StaticExercise.objects.create(\n            course_module=self.module,\n            category=self.category,\n            url='e1',\n            name=\"Test Exercise\",\n            exercise_page_content='$$exercise$$content',\n            submission_page_content='$$exercise$$received',\n            points_to_pass=0,\n            max_points=100,\n            order=1,\n        )\n        self.exercise2 = StaticExercise.objects.create(\n            course_module=self.module,\n            category=self.category,\n            url='e2',\n            name=\"Test Exercise 2\",\n            exercise_page_content='$$exercise2$$content',\n            submission_page_content='$$exercise2$$received',\n            points_to_pass=10,\n            max_points=100,\n            order=2,\n        )\n        self.exercise3 = StaticExercise.objects.create(\n            course_module=self.module2,\n            category=self.category,\n            url='e3',\n            name=\"Test Exercise 3\",\n            exercise_page_content='$$exercise3$$content',\n            submission_page_content='$$exercise3$$received',\n            points_to_pass=0,\n            max_points=100,\n        )\n        self.exercise0 = BaseExercise.objects.create(\n            course_module=self.module0,\n            category=self.category,\n            url='b0',\n            name=\"Base Exercise 0\",\n            service_url=\"http://localhost/\",\n            points_to_pass=0,\n            max_points=100,\n            min_group_size=1,\n            max_group_size=2,\n        )\n\n    @classmethod\n    def setUpSubmissions(self):\n\n        self.submission = Submission.objects.create(\n            exercise=self.exercise,\n            submission_data={'submission':1},\n            feedback='$$submission$$feedback',\n        )\n        self.submission.submitters.add(self.student.userprofile)\n        self.submission.set_points(1,2)\n        self.submission.set_ready()\n        self.submission.save()\n\n        self.submission2 = Submission.objects.create(\n            exercise=self.exercise,\n            submission_data={'submission':2},\n        )\n        self.submission2.submitters.add(self.student.userprofile)\n\n        self.submission3 = Submission.objects.create(\n            exercise=self.exercise2,\n            submission_data={'submission':3},\n        )\n        self.submission3.submitters.add(self.student.userprofile)\n        self.submission3.submitters.add(self.user.userprofile)\n", "path": "lib/testdata.py"}]}