Give please example how to run specific test (bench run-tests --test)

Could you please give example how to run one specific case?

I try like this:

frappe@erpnext:~/frappe-bench$ bench run-tests --test frappe.tests.test_email.TestEmail

I expected: Only specific case to be run.
Result: all tests are running.

and also this way doesn’t work:

frappe@erpnext:~/frappe-bench$ bench run-tests --test /apps/frappe/frappe/core/doctype/user/test_user.py

How should I run test folder, test case, test method? Can I do something like in nosetest framework?

  • For run a specific test - test_suites/test_example_folder/test_example.py:TestMethods.test_example
  • For run some test class - test_suites/test_example_folder/test_example.py:TestMethods
  • For run some file with test - test_suites/test_example_folder/test_example.py
  • For run all folder with tests - test_suites/test_example_folder

Run tests for a doctype

bench run-tests --doctype User

Run a specific case in User

bench run-tests --doctype User --test test_get_value

2 Likes

Hi all,

picking up on this, it would be very helpful to be able to run specific tests. E.g. run TestMoney from frappe.tests.test_utils without running the whole --app frappe

Is this possible in the meantime? I have observed that

$ bench run-tests --test TestMoney

which I would expect to run this and only this test will run all tests. As it is part of the utils, I can not narrow it down to a doctype, only the full app (frappe), which then again ignores the --test argument.

1 Like

To run individual unit tests in a module independently without any test-records fixtures. This helped me

bench run-tests --module \
        "custom_app.doctype.custom_doctype.test_file" \
        --test "test_name" \
        --skip-test-records --skip-before-tests

To run all the test cases in the test file simply skip the --test argument

bench run-tests --module \
        "custom_app.doctype.custom_doctype.test_file" \
        --skip-test-records --skip-before-tests

I am yet to figure out how to debug test case in VS Code the way we can debug the running bench.
Have raised a question for the same:
https://discuss.frappe.io/t/how-to-debug-unit-tests-in-frappe-with-vs-code/69069

1 Like

If you are using vim, you can use this vim plugin to run specific test directly from the editor.