0

I got the following project

project
│   README.md
│  
│
└───workers
│   └───func
│       │   func.py

│   
└───tests
│   └───__init__,py
│   └───func
│       │   test_foo.py

func.py :

import os


AUTH_DOMAIN = os.getenv("AUTH_DOMAIN")
assert AUTH_DOMAIN

def foo():
  return AUTH_DOMAIN

test_func.py:

import os

import pytest


@pytest.mark.parametrize("domain, location", [
    ("a.com", "a.com"),
    ("b.com", "b.com")
])
def test_me(domain, location):
    os.environ['AUTH_DOMAIN'] = domain
    from workers.func.func import foo
    res = foo()
    assert res == location
    del os.environ['AUTH_DOMAIN']

at the moment the second test fail because AUTH_DOMAIN is still with the value from the first test

# result in second run
assert 'a.com' == 'b.com'

how can I reimport and update the env param?

helpper
  • 2,058
  • 4
  • 13
  • 32
  • 1
    Simply mock `AUTH_DOMAIN` and test what `foo()` returns. No need to test whether `os.getenv`/`setenv` work correctly - this is already done in stdlib. – hoefling May 07 '21 at 00:01

1 Answers1

0

Looks like you can find answer here: Reimport a module in python while interactive. You can reload module using reload function in python

Maksym Sivash
  • 63
  • 1
  • 6