Commit 7d08f078 authored by Kirill Smelkov's avatar Kirill Smelkov

golang/_gopath_test: Redo $GOPATH set/restore via fixture

Currently gimport tests depend on module-level setup_module /
teardown_module, which require for gimport tests to be in separate file.

Redo the test not to depend on global module-level state and
setup/teardown. This allows e.g. to merge gimport tests into
golang_test.py if/when we want/need to.
parent 3e5b5f01
...@@ -21,23 +21,21 @@ from __future__ import print_function, absolute_import ...@@ -21,23 +21,21 @@ from __future__ import print_function, absolute_import
import os, os.path import os, os.path
from golang._gopath import gimport from golang._gopath import gimport
import pytest
GOPATH_orig = None # tgopath sets GOPATH to testdata/src during test execution.
@pytest.fixture
def setup_module(): def tgopath():
# set GOPATH to testdata/src gopath = os.environ.get('GOPATH')
global GOPATH_orig
GOPATH_orig = os.environ.get('GOPATH')
os.environ['GOPATH'] = '%s/testdata' % (os.path.dirname(__file__),) os.environ['GOPATH'] = '%s/testdata' % (os.path.dirname(__file__),)
yield
def teardown_module(): if gopath is None:
if GOPATH_orig is None:
del os.environ['GOPATH'] del os.environ['GOPATH']
else: else:
os.environ['GOPATH'] = GOPATH_orig os.environ['GOPATH'] = gopath
def test_import_module(): def test_import_module(tgopath):
hello = gimport('lab.nexedi.com/kirr/hello') hello = gimport('lab.nexedi.com/kirr/hello')
assert hello.TAG == 'gopath: test: hello.py' assert hello.TAG == 'gopath: test: hello.py'
hello.TAG = 'loaded' hello.TAG = 'loaded'
...@@ -51,7 +49,7 @@ def test_import_module(): ...@@ -51,7 +49,7 @@ def test_import_module():
assert hello.TAG == 'loaded', 'module was reloaded' assert hello.TAG == 'loaded', 'module was reloaded'
def test_import_package(): def test_import_package(tgopath):
world = gimport('lab.nexedi.com/kirr/world') world = gimport('lab.nexedi.com/kirr/world')
assert world.TAG == 'gopath: test: world/__init__.py' assert world.TAG == 'gopath: test: world/__init__.py'
world.TAG = 'loaded' world.TAG = 'loaded'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment