I have Processor
class:
class Processor:
def __init__(self, session_provider):
self.session_provider = session_provider
def run(self):
...
self.session_provider.get_session().stop()
I don’t want session to be closed at the end of run
method, but later. I tried to temporarily change it with patch
:
import unittest
from unittest.mock import Mock, MagicMock, patch
from src.components.processor import Processor
class TestProcessor(unittest.TestCase):
def test_run(self):
...
with('src.components.processor.self.session_provider.get_session.stop', new_callable=Mock()):
processor.run()
But I’m receiving error:
AttributeError: module 'src.components.processor' has no attribute 'self'
How can I fix this?
2
I’ve found that I need to patch the end call, not the nested path:
with patch('pyspark.sql.SparkSession.stop', new_callable = Mock()):
...
processor.run()