I have a unittest.TestCase with a very heavy setup class
I would like to run it using a mock if the code is launched as main, and run the full data check if it runs trough an import as following:
import unittest
from utilities import create_full_data,create_mock_data
if __name__ == "__main__":
print(' I want to run this block if code starts from here')
data_to_check=create_mock_data()
else:
print(' I want to run this block if imported')
data_to_check = create_full_data()
class Test_payer_seg(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.data_to_test = data_to_check
def test_data_qaulity(self):
self.assertTrue(1==1)
The problem seems to occur since under the hood nosetests detects is as python tests and runs it as an internal process, hence __name__ can't possibly become 'main'.
How can I create a flow that runs it as mock if it is launched a main?
Note that this issue may happen since I'm running it using pycharm