chmp / ipytest

Pytest in IPython notebooks.
MIT License
314 stars 17 forks source link

using ipytest inside databricks #47

Closed tade0726 closed 4 years ago

tade0726 commented 4 years ago

I wish to use ipytest in databricks, but I ran into an error like below.

I notice that this is something related to the databricks' mechanism: https://menziess.github.io/howto/test/code-in-databricks-notebooks/

Is it possible we can introduce ipytest in databricks?


My cells:

%%run_pytest[clean] -qq

def test_get_label_dir():
  assert get_label_dir("/test/daisy") == "daisy"

Error:

TypeError: run_cell() missing 1 required positional argument: 'raw_cell'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<command-994187> in <module>
----> 1 get_ipython().run_cell_magic('run_pytest[clean]', '-qq', '\ndef test_get_label_dir():\n  assert get_label_dir("/test/daisy") == "daisy"\n')

/databricks/python/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2350             with self.builtin_trap:
   2351                 args = (magic_arg_s, cell)
-> 2352                 result = fn(*args, **kwargs)
   2353             return result
   2354 

</databricks/python/lib/python3.7/site-packages/decorator.py:decorator-gen-120> in run_pytest_clean(self, line, cell)

/databricks/python/lib/python3.7/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):
chmp commented 4 years ago

Hi @tade0726 . Thanks for reporting this issue. I am not using databricks myself, so it's really hard for me to debug. My feeling is that the magic mechanism somehow works differently in Databricks. Could you try running it manually? Maybe that would be an option. You code should be more or less the same as

ipytest.clean_tests()

# <your code>
def test_get_label_dir():
  assert get_label_dir("/test/daisy") == "daisy"

ipytest.run(["-qq"])

Meanwhile I'll also try to ping Databricks on twitter maybe they're willing to support here.

chmp commented 4 years ago

Since there is no feedback from op or databricks, I'll close this as not supported.