
On Thu, Mar 22, 2018 at 01:06:56PM +0100, Katerina Koukiou wrote:
Also add flake8 target in tests Makefile and rewrite some parts to be more pythonic.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- HACKING.md | 2 +- test/Makefile.am | 15 ++++++++++++--- test/conftest.py | 15 +++++++++++++++ test/libvirttest.py | 51 ++++++++++++++++++++++++++++----------------------- test/test_connect.py | 35 +++++++++++++++-------------------- test/test_domain.py | 39 +++++++++++++++++---------------------- test/travis-run | 4 ++-- 7 files changed, 90 insertions(+), 71 deletions(-) create mode 100644 test/conftest.py
diff --git a/HACKING.md b/HACKING.md index 75aa6d0..30d321c 100644 --- a/HACKING.md +++ b/HACKING.md @@ -35,7 +35,7 @@ Running from git repository make check ```
- The test tool requires python3 and python3-dbus. + The test tool requires python3, pytest and python3-dbus.
We should explicitly say that we need python3-pytest.
* To run libvirt-dbus directly from the build dir without installing it diff --git a/test/Makefile.am b/test/Makefile.am index d3997f3..554c433 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,17 +1,26 @@ test_helpers = \ - libvirttest.py + libvirttest.py \ + conftest.py
test_programs = \ test_connect.py \ test_domain.py
-TESTS = $(test_programs) - EXTRA_DIST = \ $(test_helpers) \ $(test_programs) \ travis-run
+TEST_PATH=./
Just a hint, this is never a good idea, it's always better to use absolute path if possible, in this case it could be TEST_PATH = $(abs_top_srcdir)/test
+ +lint: + flake8 --exclude=.tox --ignore=E501
I'm not sure, whether we need to run flake8 on the test files, I would leave it out for now, we can add it later.
+ +test: + py.test --verbose --color=yes $(TEST_PATH)
This would not work as expected, the py.test is the same as py.test-3.
+ +check: lint test +
We don't need to change the makefile at all since we can make the test_connect.py and test_domain.py as a standalone executable, see my notes below.
TESTS_ENVIRONMENT = \ abs_top_builddir=$(abs_top_builddir) \ VIRT_DBUS_INTERFACES_DIR=$(abs_top_srcdir)/data diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000..a468599 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,15 @@ +import os +import subprocess +import pytest
Nitpick: alphabetic order is nicer :). Anyway, the test changes and the rewrite to pytest is OK. I'm attaching a patch with changes that would make the tests as standalone executable. In this case the patch is better then describing it. If you agree with the changes you can send a v2. With these changes it should be possible to run "make check" to run the whole test suite or "./run test/test_connect.py [pytest args]" to run the single test with pytest arguments. Thanks for the patch! Pavel