Support Questions
Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Innovation Accelerator group hub.

Is there way to run a single Ambari python unit test using mvn test command?

Cloudera Employee

e.g. mvn -Dtest=TestHDP23StackAdvisor test

1 ACCEPTED SOLUTION

Mentor
5 REPLIES 5

Mentor

is there a specific unit test you're referring to? Ambari unit tests are written in Java using JUnit, so you'd use mvn, just like your example. Here's the development guide, https://cwiki.apache.org/confluence/display/AMBARI... and here's latest build reports https://builds.apache.org/job/Ambari-trunk-Commit/... For general python unit testing and running single tests, you can do so by referring to Python docs:

The unittest module can be used from the command line to run tests from modules, classes or even individual test methods:

python -m unittest test_module1 test_module2
python -m unittest test_module.TestClass
python -m unittest test_module.TestClass.test_method

Cloudera Employee

Hi Artem,

Thanks a lot for your input. I was looking to test stack advisor recommendations and validations.

e.g. ambari/ambari-server/src/test/python/stacks/2.3/common/test_stack_advisor.py

Mentor

Cloudera Employee

Thanks again!

Here is what worked for me (using python 2.6.6). Still need to investigate how to run the test from ambari root directory.

$ pip install discover
$ export PYTHONPATH=~/git/ambari/ambari-common/src/test/python
$ cd ~/git/ambari/ambari-server/src/test/python/stacks/2.3/common
$ python -m discover -v
Test that HAWQSTANDBY is not recommended on a single node cluster ... ok
...
----------------------------------------------------------------------
Ran 21 tests in 0.318s
OK

Expert Contributor

Hi FYI i have used

/git/ambari/ambari-common/src/main/python as oppose to /git/ambari/ambari-common/src/test/python