-
Notifications
You must be signed in to change notification settings - Fork 17
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
Question about running in Jypiter notebooks #27
Comments
Hi @tsemana. The problems problems you describe sound very much, like import ipytest
ipytest.config(rewrite_asserts=True, magics=True)
__file__ = "INSERT YOUR NOTEBOOK FILENAME HERE" Hopfefully that fixes the issues. |
@chmp thank you for the response. Unfortunately I did have that block. Here is the entirety of the cells I'm trying to get it to run: cell1 (adding libraries to emr cluster running the notebook) sc.install_pypi_package("pytest")
sc.install_pypi_package("ipytest")
sc.install_pypi_package("ipython") cell2 import pytest
import ipytest
ipytest.config(rewrite_asserts=True, magics=True)
__file__ = "udacity-tony-test-emr.ipynb" cell3 def my_func(x):
return x // 2 * 2 cell4 # define the tests
def test_my_func():
assert my_func(0) == 0
assert my_func(1) == 0
assert my_func(2) == 2
assert my_func(3) == 2 cell5 # execute the tests via pytest, arguments are passed to pytest
ipytest.run('-qq') response ERROR: not found: /mnt/tmp/1008237126276784108
(no name '/mnt/tmp/1008237126276784108' in any of []) cell6 %%run_pytest[clean] -qq response unknown magic command '%run_pytest[clean]'
UnknownMagic: unknown magic command '%run_pytest[clean]' With each attempt at running the cells from a restart of the notebook, the following series of errors always show on running Cell2 - where I import The first time the cell is run:
When I rerun the cell, the error message changes:
When I re-run the cell a third time, there are is no error. This series happens consistently, regardless of how long I wait between running cell1 and cell2 (though I know that should not matter). When I call <Config rewrite_asserts=True, magics=True, tempfile_fallback=False, clean='[Tt]est*', addopts=(), raise_on_error=False, run_in_thread=False> Hope this gives enough details to assess what's going wrong. |
Hm. Strange. From above's error message, my guess would be, you're not running inside a standard Jupyter notebook with an IPython kernel. Otherwise, I would expect that What is the environment you're running in? To set expectations: at the moment ipytest is pretty much hardwired around the IPython kernel, not sure it's easy to support other environments. |
Ok, that would explain it then if that's a hard limitation. I'm running on the notebook on an AWS EMR cluster running on PySpark kernel. I was hoping to be able to test in the notebook to validate ETL processes. |
@chmp - from you comment in the issue logged in the pytest repo:
pytest-dev/pytest#2268 (comment)
I'm new to using Python / Jupyiter and found this entry, but I'm sure I'm doing something wrong because I can't get the simple examples to work. Using the first example, I get stuck after the second cell with
More generally - I'm not sure how to 'execute' the test. Whether this means just calling the function normally, since using
%%run_pytest
will result in the same error above, but calling the function does not return especially helpful results.I found the
Example.ipynb
file and running them provides the a different error when I runipytest.run('-qq')
For context, I'm running the jupyter notebook on and AWS EMR instance running a PySpark kernel. Relevant installed versions:
Thanks for your help.
The text was updated successfully, but these errors were encountered: