project\
src\
__init__.py
tests\
__init__.py
stubs\r_json_response_expired.json
Within my test I have to load a JSON file. this.
@patch('requests.post')
def test_subscription_delete_only_if_invalid(self, mock_post):
with app.app_context():
expires_at = datetime.utcnow()
m = self.inject_expired_r_json()
def inject_expired_r_json(self):
with open('stubs/r_json_response_expired.json') as fb_file:
receipt_response = json.load(fb_file)
m = MagicMock()
m.json = MagicMock(name='json')
m.json.return_value = receipt_response
return m
When running the test VS Code shows:
FileNotFoundError: [Errno 2] No such file or directory: 'stubs/r_json_response_expired.json'
I have .env
in my project:
PYTHONPATH=./src
And in settings.json (VS CODE)
"terminal.integrated.env.osx": {
"PYTHONPATH": "${workspaceFolder}/src"
},
"python.envFile": "${workspaceFolder}/.env"
I don't like changing the path in the test to avoid breaking PyCharm, if I happen to switch the IDE.