bench run-tests broken
See original GitHub issueDescription of the issue
I wrote a unittest for a DocType named “ITUC Urlaubsvergleich”. I used
bench run-tests --doctype "ITUC Urlaubsvergleich" --skip-test-records --skip-before-tests
and
bench run-tests --doctype "ITUC Urlaubsvergleich"
to start the tests but got some exceptions I don’t understand, see below.
Also all records from the DocType “Leave Application” were deleted.
Context information (for bug reports)
This is what I did before the exceptions happened:
frappe@erpnextthkr:~/frappe-bench$ bench run-tests --doctype "ITUC Urlaubsvergleich"
Testing is disabled for the site!
You can enable tests by entering following command:
bench --site erpnextthkr.schloss.ituc.de set-config allow_tests true
frappe@erpnextthkr:~/frappe-bench$ bench --site erpnextthkr.schloss.ituc.de set-config allow_tests true
frappe@erpnextthkr:~/frappe-bench$ bench run-tests --doctype "ITUC Urlaubsvergleich" --skip-test-records --skip-before-tests
I read the guides https://frappeframework.com/docs/v13/user/en/guides/automated-testing/unit-testing and https://frappeframework.com/docs/v13/user/en/guides/automated-testing/unit-testing.
Seems pretty easy to use and straight, but I don’t understand whats going wrong.
Output of bench version
erpnext 13.19.0
frappe 13.19.0
Steps to reproduce the issue
- Create a new DocType
- Create a new unittest.
- Run test: bench run-tests --doctype “My new DocType”
Observed result
Exceptions occur, all data from Doctype “Leave Application” is deleted.
Expected result
unittest gets executed without the nonsense mentioned above.
Stacktrace / full error message
frappe@erpnextthkr:~/frappe-bench$ bench run-tests --doctype “ITUC Urlaubsvergleich”
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 104, in <module>
main()
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 19, in main
click.Group(commands=commands)(prog_name='bench')
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/utils.py", line 583, in run_tests
ui_tests=ui_tests, doctype_list_path=doctype_list_path, failfast=failfast)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 70, in main
ret = run_tests_for_doctype(doctype, verbose, tests, force, profile, failfast=failfast, junit_xml_output=junit_xml_output)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 171, in run_tests_for_doctype
make_test_records(doctype, verbose=verbose, force=force)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 278, in make_test_records
make_test_records(options, verbose, force)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 279, in make_test_records
make_test_records_for_doctype(options, verbose, force)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 329, in make_test_records_for_doctype
frappe.local.test_objects[doctype] += make_test_objects(doctype, test_module.test_records, verbose, force)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 380, in make_test_objects
d.insert()
File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 234, in insert
self._validate_links()
File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 837, in _validate_links
frappe.LinkValidationError)
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 439, in throw
msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list)
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 418, in msgprint
_raise_exception()
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 372, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.LinkValidationError: Could not find Default Holiday List: _Test Holiday List
frappe@erpnextthkr:~/frappe-bench$ bench run-tests --doctype “ITUC Urlaubsvergleich” --skip-test-records --skip-before-tests
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 104, in <module>
main()
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 19, in main
click.Group(commands=commands)(prog_name='bench')
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 27, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/utils.py", line 583, in run_tests
ui_tests=ui_tests, doctype_list_path=doctype_list_path, failfast=failfast)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 70, in main
ret = run_tests_for_doctype(doctype, verbose, tests, force, profile, failfast=failfast, junit_xml_output=junit_xml_output)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 174, in run_tests_for_doctype
return _run_unittest(modules, verbose=verbose, tests=tests, profile=profile, failfast=failfast, junit_xml_output=junit_xml_output)
File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 186, in _run_unittest
frappe.db.begin()
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 755, in begin
self.sql("START TRANSACTION")
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 126, in sql
self.check_transaction_status(query)
File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 265, in check_transaction_status
raise Exception('This statement can cause implicit commit')
Exception: This statement can cause implicit commit
Additional information
OS version / distribution, Frappe
install method, etc.
Debian buster
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
put a print statement here
https://github.com/frappe/frappe/blob/b5cf4a15c0a9f96b240e5da9f852be088dbb4ddb/frappe/database/database.py#L278-L279
and here
https://github.com/frappe/frappe/blob/b5cf4a15c0a9f96b240e5da9f852be088dbb4ddb/frappe/database/database.py#L288-L291
You’ll figure out which queries are causing writes but not committing.
try the below