[Freeipa-devel] [freeipa PR#442][synchronized] Add option to run tests in-tree and out-of-tree mode

2017-02-09 Thread tiran
   URL: https://github.com/freeipa/freeipa/pull/442
Author: tiran
 Title: #442: Add option to run tests in-tree and out-of-tree mode
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/442/head:pr442
git checkout pr442
From fa021e8e631b555068d6f7ab34abdd0a4fe844e1 Mon Sep 17 00:00:00 2001
From: Christian Heimes 
Date: Wed, 8 Feb 2017 13:29:38 +0100
Subject: [PATCH] Add option to run tests in-tree and out-of-tree mode

By default ipa-run-tests and pytest auto-detect the presence of
../ipasetup.py.in and run tests in-tree mode when the file exists. The
option can be overriden with ipa-run-tests --in-tree=true/false.

Signed-off-by: Christian Heimes 
---
 ipatests/conftest.py | 28 +++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/ipatests/conftest.py b/ipatests/conftest.py
index 6d8ba60..df8d919 100644
--- a/ipatests/conftest.py
+++ b/ipatests/conftest.py
@@ -3,6 +3,8 @@
 #
 from __future__ import print_function
 
+import os
+
 from ipalib import api
 from ipalib.cli import cli_plugins
 try:
@@ -11,6 +13,9 @@
 ipaserver = None
 
 
+HERE = os.path.dirname(os.path.abspath(__file__))
+
+
 pytest_plugins = [
 'ipatests.pytest_plugins.additional_config',
 'ipatests.pytest_plugins.beakerlib',
@@ -71,9 +76,30 @@ def pytest_configure(config):
 config.option.doctestmodules = True
 
 
+def pytest_addoption(parser):
+def truefalse(arg):
+if arg.lower() == 'true':
+return True
+if arg.lower() == 'false':
+return False
+return arg  # triggers an error later
+
+in_tree = os.path.isfile(os.path.join(HERE, os.pardir, 'ipasetup.py.in'))
+group = parser.getgroup("IPA integration tests")
+group.addoption(
+'--in-tree',
+dest="ipa_in_tree",
+type=truefalse,
+choices=(True, False),
+default=in_tree,
+help="Run IPA tests in-tree (default: auto-detect ../ipasetup.py.in)"
+)
+
+
 def pytest_cmdline_main(config):
 api.bootstrap(
-context=u'cli', in_server=False, in_tree=True, fallback=False
+context=u'cli', in_server=False, in_tree=config.option.ipa_in_tree,
+fallback=False
 )
 for klass in cli_plugins:
 api.add_plugin(klass)
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

[Freeipa-devel] [freeipa PR#442][synchronized] Add option to run tests in-tree and out-of-tree mode

2017-02-08 Thread tiran
   URL: https://github.com/freeipa/freeipa/pull/442
Author: tiran
 Title: #442: Add option to run tests in-tree and out-of-tree mode
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/442/head:pr442
git checkout pr442
From b000b01d92cab834c808d0c6792d76cd4389893b Mon Sep 17 00:00:00 2001
From: Christian Heimes 
Date: Wed, 8 Feb 2017 13:29:38 +0100
Subject: [PATCH] Add option to run tests in-tree and out-of-tree mode

By default ipa-run-tests and pytest auto-detect the presence of
../ipasetup.py.in and run tests in-tree mode when the file exists. The
option can be overriden with ipa-run-tests --in-tree=true/false.

Signed-off-by: Christian Heimes 
---
 ipatests/conftest.py | 28 +++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/ipatests/conftest.py b/ipatests/conftest.py
index 6d8ba60..df8d919 100644
--- a/ipatests/conftest.py
+++ b/ipatests/conftest.py
@@ -3,6 +3,8 @@
 #
 from __future__ import print_function
 
+import os
+
 from ipalib import api
 from ipalib.cli import cli_plugins
 try:
@@ -11,6 +13,9 @@
 ipaserver = None
 
 
+HERE = os.path.dirname(os.path.abspath(__file__))
+
+
 pytest_plugins = [
 'ipatests.pytest_plugins.additional_config',
 'ipatests.pytest_plugins.beakerlib',
@@ -71,9 +76,30 @@ def pytest_configure(config):
 config.option.doctestmodules = True
 
 
+def pytest_addoption(parser):
+def truefalse(arg):
+if arg.lower() == 'true':
+return True
+if arg.lower() == 'false':
+return False
+return arg  # triggers an error later
+
+in_tree = os.path.isfile(os.path.join(HERE, os.pardir, 'ipasetup.py.in'))
+group = parser.getgroup("IPA integration tests")
+group.addoption(
+'--in-tree',
+dest="ipa_in_tree",
+type=truefalse,
+choices=(True, False),
+default=in_tree,
+help="Run IPA tests in-tree (default: auto-detect ../ipasetup.py.in)"
+)
+
+
 def pytest_cmdline_main(config):
 api.bootstrap(
-context=u'cli', in_server=False, in_tree=True, fallback=False
+context=u'cli', in_server=False, in_tree=config.option.ipa_in_tree,
+fallback=False
 )
 for klass in cli_plugins:
 api.add_plugin(klass)
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code