With the following pytest
file:
(import pytest [mark])
(import pathlib [Path])
(require oreo [with-cwd])
(defn [mark.with-cwd] test-with-cwd [cookies]
(let [ cwd (.cwd Path) ]
(with-cwd cookies (assert (= (.cwd Path) cookies)))
(assert (= (.cwd Path) cwd))))
I'm getting the following error:
Traceback (most recent call last):
File "/home/shadowrylander/shadowrylander/sylveon/syvlorg/oreo/tests/test-with-cwd.hy", line 7, in test_with_cwd
(with-cwd cookies (assert (= (.cwd Path) cookies)))
NameError: name 'os' is not defined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/shadowrylander/shadowrylander/sylveon/syvlorg/oreo/tests/test-with-cwd.hy", line 7, in test_with_cwd
(with-cwd cookies (assert (= (.cwd Path) cookies)))
NameError: name 'os' is not defined
The cookies
fixture is as follows:
@pytest.fixture()
def cookies(request):
from pathlib import Path
return Path(request.config.rootdir).expanduser().resolve(strict = True) / "cookies"
And finally, with-cwd
in the oreo
module is basically:
(eval-and-compile (import os hy))
(defmacro with-cwd [dir #* body]
(setv cwd (hy.gensym))
`(let [ ~cwd (.cwd Path) ]
(try (.chdir os ~dir)
~@body
(finally (.chdir os ~cwd)))))
I am using hy
version 0.25.0
. The test works if I import os
in the test file itself.
Update
This new one does not seem to work either, giving me the same error:
(defmacro with-cwd [dir #* body]
(setv cwd (hy.gensym)
os (hy.gensym))
`(let [ ~cwd (.cwd Path) ]
(import os :as ~os)
(try ((. ~os chdir) ~dir)
~@body
(finally ((. ~os chdir) ~cwd)))))