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

Use pytest plugin mechanism to conditionally skip tests requiring Julia runtime #237

Merged
merged 7 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ nosetests.xml
# PyCharm
.idea/*

# Test files
*test.py

# created by distutils during build process
MANIFEST

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ $ tox
The full syntax for invoking `tox` is

```shell
[PYJULIA_TEST_REBUILD=yes] [JULIA_EXE=<julia>] tox [options] [-- pytest options]
[PYJULIA_TEST_REBUILD=yes] [PYJULIA_TEST_RUNTIME=<julia>] tox [options] [-- pytest options]
```

* `PYJULIA_TEST_REBUILD`: *Be careful using this environment
Expand All @@ -405,14 +405,14 @@ The full syntax for invoking `tox` is
also that it does not work if you unconditionally set `PYTHON`
environment variable in your Julia startup file.

* `JULIA_EXE`: `julia` executable to be used for testing.
* `PYJULIA_TEST_RUNTIME`: `julia` executable to be used for testing.

* Positional arguments after `--` are passed to `pytest`.

For example,

```console
$ PYJULIA_TEST_REBUILD=yes JULIA_EXE=~/julia/julia tox -e py37 -- -s
$ PYJULIA_TEST_REBUILD=yes PYJULIA_TEST_RUNTIME=~/julia/julia tox -e py37 -- -s
```

means to execute tests with
Expand Down
10 changes: 7 additions & 3 deletions julia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,18 +530,22 @@ class LibJulia(BaseLibJulia):

An easy way to create a `LibJulia` object is `LibJulia.load`:

>>> api = LibJulia.load()
>>> api = LibJulia.load() # doctest: +SKIP

Or, equivalently,

>>> api = LibJulia.load(julia="julia")
>>> api = LibJulia.from_juliainfo(JuliaInfo.load())
>>> api = LibJulia.load(julia="julia") # doctest: +SKIP
>>> api = LibJulia.from_juliainfo(JuliaInfo.load()) # doctest: +SKIP

You can pass a path to the Julia executable using `julia` keyword
argument:

>>> api = LibJulia.load(julia="PATH/TO/CUSTOM/julia") # doctest: +SKIP

.. Do not run doctest with non-default libjulia.so.
>>> _ = getfixture("julia")
>>> api = get_libjulia()

Path to the system image can be configured before initializing Julia:

>>> api.image_file # doctest: +SKIP
Expand Down
34 changes: 34 additions & 0 deletions julia/pytestplugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import print_function, absolute_import

import pytest


def pytest_addoption(parser):
import os

parser.addoption(
"--no-julia",
action="store_false",
dest="julia",
help="Skip tests that require julia.",
)
parser.addoption(
"--julia-runtime",
help="""
Julia executable to be used. Defaults to environment variable
`$PYJULIA_TEST_RUNTIME`.
""",
default=os.getenv("PYJULIA_TEST_RUNTIME", "julia"),
)


@pytest.fixture(scope="session")
def julia(request):
""" pytest fixture for providing a `Julia` instance. """
if not request.config.getoption("julia"):
pytest.skip("--no-julia is given.")

from julia.core import Julia

jl = Julia(runtime=request.config.getoption("julia_runtime"), debug=True)
return jl
4 changes: 2 additions & 2 deletions julia/with_rebuilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def main(args=None):
variable in your Julia startup file.
""")
parser.add_argument(
'--julia', default=os.getenv('JULIA_EXE', 'julia'),
'--julia', default=os.getenv('PYJULIA_TEST_RUNTIME', 'julia'),
help="""
Julia executable to be used.
Default to the value of environment variable JULIA_EXE if set.
Default to the value of environment variable PYJULIA_TEST_RUNTIME if set.
""")
parser.add_argument(
'command', nargs='+',
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def pyload(path):
"console_scripts": [
"python-jl = julia.python_jl:main",
],
"pytest11": [
"pyjulia = julia.pytestplugin",
],
},
# We bundle Julia scripts etc. inside `julia` directory. Thus,
# this directory must exist in the file system (not in a zip
Expand Down
9 changes: 9 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest


@pytest.fixture(scope="session")
def Main(julia):
""" pytest fixture for providing a Julia `Main` name space. """
from julia import Main

return Main
5 changes: 2 additions & 3 deletions test/test_compatible_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ def is_dynamically_linked(executable):


@pytest.mark.parametrize("python", incompatible_pythons)
def test_incompatible_python(python):
from .test_core import julia
def test_incompatible_python(python, julia):

if julia.eval("(VERSION.major, VERSION.minor)") == (0, 6):
# Julia 0.6 implements mixed version
Expand All @@ -131,7 +130,7 @@ def test_incompatible_python(python):
"""
import os
from julia import Julia
Julia(runtime=os.getenv("JULIA_EXE"), debug=True)
Julia(runtime=os.getenv("PYJULIA_TEST_RUNTIME"), debug=True)
""",
)

Expand Down
Loading