Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Use @pytest.mark.forked to fix test_without_init #1464

Merged
merged 8 commits into from
Jul 14, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions tests/python/test_runtime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import taichi as ti
from taichi import make_temp_file
import sys, os, copy
from contextlib import contextmanager
import pytest
Expand Down Expand Up @@ -117,24 +116,18 @@ def test_init_bad_arg():
ti.init(_test_mode=True, debug=True, foo_bar=233)


@pytest.mark.forked
def test_without_init():
# We want to check if Taichi works well without ``ti.init()``.
# But in test ``ti.init()`` will always be called in last ``@ti.all_archs``.
# So we have to create a new Taichi instance, i.e. test in a sandbox.
content = '''
import taichi as ti
assert ti.cfg.arch == ti.cpu

x = ti.var(ti.i32, (2, 3))
assert x.shape == (2, 3)

x[1, 2] = 4
assert x[1, 2] == 4
'''
filename = make_temp_file()
with open(filename, 'w') as f:
f.write(content)
assert os.system(f'{sys.executable} {filename}') == 0
assert ti.cfg.arch == ti.cpu

x = ti.var(ti.i32, (2, 3))
assert x.shape == (2, 3)

x[1, 2] = 4
assert x[1, 2] == 4


@ti.all_archs
Expand Down