Open midumitrescu opened 2 years ago
Hey @midumitrescu! It looks like you're trying to pass in a bunch of non-JSON serializable types into the testbook reference function call - types like non-native numpy array implementations, and a function type.
If you'd like to call your function with such types, we have a way of injecting all your code into the notebook, by using tb.inject
So your test would look something like so:
def test_some_small_function(tb):
tb.inject("""
import numpy as np
from assertpy import assert_that
from pytest import fixture
test_w_1_0 = np.array([1])
test_no_bias = np.array([0])
test_w_2_1 = np.array([1])
print(locals())
assert_that(some_function(0, test_w_1_0, test_no_bias, test_w_2_1, np.sign)).contains([0, 1, -1])
""")
(FYI: You would not need to worry about indentation because we dedent the code string before injecting)
Let me know if that solves your issue. Thanks!
Hello,
i have following test:
having in the notebook:
and I get the following TypeError error:
I have added extra type information to make it clear to you the intend of the code.
Tests inside the notebook are running successfully
test_h2.py:12 (test_some_small_function) self = <testbook.client.TestbookNotebookClient object at 0x7f9ef824d2e0> cell = [8], kwargs = {}, cell_indexes = [8], executed_cells = [], idx = 8
../venv/lib/python3.8/site-packages/testbook/client.py:133:
args = (<testbook.client.TestbookNotebookClient object at 0x7f9ef824d2e0>, {'id': '6ac327d5', 'cell_type': 'code', 'metadata'...0m\x1b0;31mTypeError\x1b[0m: unsupported operand type(s) for -: 'str' and 'str'"]} for -: 'str' and 'str'"]}]}, 8) kwargs = {}
../venv/lib/python3.8/site-packages/nbclient/util.py:78:
coro = <coroutine object NotebookClient.async_execute_cell at 0x7f9ef81fea40>
../venv/lib/python3.8/site-packages/nbclient/util.py:57:
self = <_UnixSelectorEventLoop running=False closed=False debug=False> future = <Task finished name='Task-48' coro=<NotebookClient.async_execute_cell() done, defined at /Users/1000ber-5078/PycharmPr...rted operand type(s) for -: \'str\' and \'str\'\nTypeError: unsupported operand type(s) for -: \'str\' and \'str\'\n')>
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py:616:
self = <testbook.client.TestbookNotebookClient object at 0x7f9ef824d2e0> cell = {'id': '6ac327d5', 'cell_type': 'code', 'metadata': {'execution': {'iopub.status.busy': '2021-10-23T15:57:12.875064Z',...x1b[0m\x1b0;31mTypeError\x1b[0m: unsupported operand type(s) for -: 'str' and 'str'"]} for -: 'str' and 'str'"]}]} cell_index = 8, execution_count = None, store_history = True
../venv/lib/python3.8/site-packages/nbclient/client.py:862:
self = <testbook.client.TestbookNotebookClient object at 0x7f9ef824d2e0> cell = {'id': '6ac327d5', 'cell_type': 'code', 'metadata': {'execution': {'iopub.status.busy': '2021-10-23T15:57:12.875064Z',...x1b[0m\x1b0;31mTypeError\x1b[0m: unsupported operand type(s) for -: 'str' and 'str'"]} for -: 'str' and 'str'"]}]} exec_reply = {'buffers': [], 'content': {'ename': 'TypeError', 'engine_info': {'engine_id': -1, 'engine_uuid': '7b8e70ee-5b55-4029-...e, 'engine': '7b8e70ee-5b55-4029-888b-a23a76f683ca', 'started': '2021-10-23T15:57:12.869603Z', 'status': 'error'}, ...}
../venv/lib/python3.8/site-packages/nbclient/client.py:765: CellExecutionError
During handling of the above exception, another exception occurred:
tb = <testbook.client.TestbookNotebookClient object at 0x7f9ef824d2e0>
test_h2.py:19:
../venv/lib/python3.8/site-packages/testbook/reference.py:85: in call return self.tb.value(code) ../venv/lib/python3.8/site-packages/testbook/client.py:273: in value result = self.inject(code, pop=True) ../venv/lib/python3.8/site-packages/testbook/client.py:237: in inject cell = TestbookNode(self.execute_cell(inject_idx)) if run else TestbookNode(code_cell)
self = <testbook.client.TestbookNotebookClient object at 0x7f9ef824d2e0> cell = [8], kwargs = {}, cell_indexes = [8], executed_cells = [], idx = 8
../venv/lib/python3.8/site-packages/testbook/client.py:135: TestbookRuntimeError
======================== 1 failed, 12 warnings in 2.97s ========================
Process finished with exit code 1