Fapiko / intellij-better-direnv

Apache License 2.0
30 stars 18 forks source link

Plugin does not work with test run configurations #34

Open Behoston opened 10 months ago

Behoston commented 10 months ago

When running test configuration (for example pytest), direnv variables are not loaded. It works fine with "standard" python run configurations.

test.py

import os
import unittest

def get_variable():
    return os.environ.get('VARIABLE')

class Test(unittest.TestCase):
    def test_direnv_variable(self):
        self.assertEqual(get_variable(), 'AAA')

if __name__ == '__main__':
    print(get_variable())

.envrc

layout python python3.12

ln -s -f .direnv/$(basename $VIRTUAL_ENV)/ 'venv'

export VARIABLE=AAA

Output when running test run:

AAA != None

Expected :None
Actual   :AAA
<Click to see difference>

Traceback (most recent call last):
  File "/home/behoston/PycharmProjects/direnv_problem/test.py", line 7, in test_direnv_variable
    self.assertEqual(os.environ.get('VARIABLE'), 'AAA')
AssertionError: None != 'AAA'

Ran 1 test in 0.003s

FAILED (failures=1)

Process finished with exit code 1

Output when running python run:

AAA

Process finished with exit code 0

Run configurations

Tests

obraz obraz

Python

obraz