Reputation: 26859
I'm looking for some basic examples of the python 2.7 unittest setUpClass() method. I'm trying to test some class methods in my module, and I've gotten as far as:
import unittest
import sys
import mymodule
class BookTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._mine = mymodule.myclass('test_file.txt', 'baz')
But I have no idea how to proceed from here to write tests utilising the object I just created.
Upvotes: 39
Views: 31184
Reputation: 17229
If you're using Django 1.8+, you should use the setUpTestData
method instead.
You can then set any attributes on the cls
object, and access them via the individual test methods on the self
object.
More information is in the Django docs.
Upvotes: 6
Reputation: 32532
In your test methods you can now access the global class atribute _mine
through self. So you can do something like this:
def test_something(self):
self.assertEqual(self._mine.attribute, 'myAttribute')
Upvotes: 40