moving to pytest idioms (some of these should be added to testing section on CONTRIBUTING)
the conftest.py has a yield_fixture called xonsh_builtins
that is a replacement for the old
mock_xonsh_env
context manager. xonsh_builtins
sets and yields builtins
To use xonsh_builtins
in a test we just specify it as an argument to the test, i.e:
def test_one(xonsh_builtins):
...
the xonsh builtins get set when the test starts and teared when the test ends.
note that there is no need to import that fixture from anywhere, fixtures that exist in conftest.py
pytest will pick up and use in all tests.
xonsh_builtins
sets __xonsh_env__
to be an empty dict. if we want to set the __xonsh_env__
to a different initial value we set it directly from xonsh_builtins.__xonsh_env__
def test_one(xonsh_builtins):
xonsh_env.__xonsh_env__ = ENV_1
...
if we want to test for different __xonsh_env__
values we can use parametrization i.e:
@pytest.mark.parametrize('env', [ENV_1, ENV_2])
def test_one(xonsh_builtins, env):
xonsh_builtins.__xonsh_env__ = env
...
this will run 2 times each time with the respective env setup.
if we want to set the same __xonsh_env__
for different tests we can create a new fixture (ty @melund ! )
i.e:
@pytest.fixture
def special_env(xonsh_builtins):
xonsh_builtins.__xonsh_env__['Strombus'] = "gigas"
def test_1(special_env):
assert True
def test_2(special_env):
assert True
i have added a TODO.txt to track progress.
tests