[Freeipa-devel] [freeipa PR#366][synchronized] Use pytest conftest.py

2017-01-05 Thread tiran
   URL: https://github.com/freeipa/freeipa/pull/366
Author: tiran
 Title: #366: Use pytest conftest.py 
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/366/head:pr366
git checkout pr366
From 4fad18a15221d9a5fd7b075a55a59b0a8d5fda3e Mon Sep 17 00:00:00 2001
From: Christian Heimes 
Date: Tue, 3 Jan 2017 18:04:53 +0100
Subject: [PATCH] Use pytest conftest.py and drop pytest.ini

Let's replace some ugly hacks with proper pytest conftest.py hooks.
Test initialization of ipalib.api is now handled in
pytest_cmdline_main(). Pytest plugins, markers and ignores are also
moved into conftest.py. Additional guards make it possible to run tests
without ipaserver installed.

I added confcutdir to ensure that pytest does not leave our project
space. Pytest used pytest.ini or setup.py before but pytest.ini is gone.

Signed-off-by: Christian Heimes 
---
 Makefile.am|  3 +-
 ipalib/__init__.py |  7 -
 ipatests/conftest.py   | 76 ++
 ipatests/ipa-run-tests | 13 +
 ipatests/pytest.ini| 23 ---
 ipatests/setup.py  |  1 -
 make-test  |  8 --
 pytest.ini |  1 -
 8 files changed, 90 insertions(+), 42 deletions(-)
 create mode 100644 ipatests/conftest.py
 delete mode 100644 ipatests/pytest.ini
 delete mode 12 pytest.ini

diff --git a/Makefile.am b/Makefile.am
index 73bd378..9bfc899 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -37,8 +37,7 @@ EXTRA_DIST = .mailmap \
 	 doc \
 	 freeipa.spec.in \
 	 ipasetup.py.in \
-	 pylintrc \
-	 pytest.ini
+	 pylintrc
 
 clean-local:
 	rm -rf "$(RPMBUILD)"
diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index aaca973..4f09090 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -949,10 +949,3 @@ def create_api(mode='dummy'):
 return api
 
 api = create_api(mode=None)
-
-if os.environ.get('IPA_UNIT_TEST_MODE', None) == 'cli_test':
-from ipalib.cli import cli_plugins
-api.bootstrap(context='cli', in_server=False, in_tree=True, fallback=False)
-for klass in cli_plugins:
-api.add_plugin(klass)
-api.finalize()
diff --git a/ipatests/conftest.py b/ipatests/conftest.py
new file mode 100644
index 000..45920de
--- /dev/null
+++ b/ipatests/conftest.py
@@ -0,0 +1,76 @@
+#
+# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
+#
+from __future__ import print_function
+
+from ipalib import api
+from ipalib.cli import cli_plugins
+try:
+import ipaserver
+except ImportError:
+ipaserver = None
+
+
+pytest_plugins = [
+'ipatests.pytest_plugins.additional_config',
+'ipatests.pytest_plugins.beakerlib',
+'ipatests.pytest_plugins.declarative',
+'ipatests.pytest_plugins.nose_compat',
+]
+# The integration plugin is not available in client-only builds.
+if ipaserver is not None:
+pytest_plugins.append('ipatests.pytest_plugins.integration')
+
+
+MARKERS = [
+'tier0: basic unit tests and critical functionality',
+'tier1: functional API tests',
+'cs_acceptance: Acceptance test suite for Dogtag Certificate Server',
+'ds_acceptance: Acceptance test suite for 389 Directory Server',
+]
+
+
+NO_RECURSE_DIRS = [
+# build directories
+'ipaclient/build',
+'ipalib/build',
+'ipaplatform/build',
+'ipapython/build',
+'ipaserver/build',
+'ipatests/build',
+# install/share/wsgi.py
+'install/share'
+]
+
+
+def pytest_configure(config):
+# add pytest markers
+for marker in MARKERS:
+config.addinivalue_line('markers', marker)
+
+# do not recurse into build directories or install/share directory.
+for norecursedir in NO_RECURSE_DIRS:
+config.addinivalue_line('norecursedirs', norecursedir)
+
+# load test classes with these prefixes.
+# addinivalue_line() adds duplicated entries.
+python_classes = config.getini('python_classes')
+for value in ['test_', 'Test']:
+if value not in python_classes:
+python_classes.append(value)
+
+# set default JUnit prefix
+if config.option.junitprefix is None:
+config.option.junitprefix = 'ipa'
+
+# always run doc tests
+config.option.doctestmodules = True
+
+
+def pytest_cmdline_main(config):
+api.bootstrap(
+context=u'cli', in_server=False, in_tree=True, fallback=False
+)
+for klass in cli_plugins:
+api.add_plugin(klass)
+api.finalize()
diff --git a/ipatests/ipa-run-tests b/ipatests/ipa-run-tests
index 53fa7b3..cafd993 100755
--- a/ipatests/ipa-run-tests
+++ b/ipatests/ipa-run-tests
@@ -34,12 +34,15 @@ import pytest
 
 import ipatests
 
-# This must be set so ipalib.api gets initialized property for tests:
-os.environ['IPA_UNIT_TEST_MODE'] = 'cli_test'
-
 # This is set to store --with-xunit report in an accessible place:
 os.environ['IPATEST_XUNIT_PATH'] = 

[Freeipa-devel] [freeipa PR#366][synchronized] Use pytest conftest.py

2017-01-04 Thread tiran
   URL: https://github.com/freeipa/freeipa/pull/366
Author: tiran
 Title: #366: Use pytest conftest.py 
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/366/head:pr366
git checkout pr366
From 45011a60f63d5471ccf85cf7549362dd7ad3cb23 Mon Sep 17 00:00:00 2001
From: Christian Heimes 
Date: Tue, 3 Jan 2017 18:04:53 +0100
Subject: [PATCH 1/2] Use pytest conftest.py

Let's replace some ugly hacks with proper pytest conftest.py hooks.
Test initialization of ipalib.api is now handled in
pytest_cmdline_main(). Pytest plugins, markers and ignores are also
moved into conftest.py. Additional guards make it possible to run tests
without ipaserver installed.
---
 ipalib/__init__.py |  7 --
 ipatests/conftest.py   | 59 ++
 ipatests/ipa-run-tests |  3 ---
 ipatests/pytest.ini| 10 -
 make-test  |  2 +-
 5 files changed, 60 insertions(+), 21 deletions(-)
 create mode 100644 ipatests/conftest.py

diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index 4a61ace..5a11f86 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -949,10 +949,3 @@ def create_api(mode='dummy'):
 return api
 
 api = create_api(mode=None)
-
-if os.environ.get('IPA_UNIT_TEST_MODE', None) == 'cli_test':
-from ipalib.cli import cli_plugins
-api.bootstrap(context='cli', in_server=False, in_tree=True, fallback=False)
-for klass in cli_plugins:
-api.add_plugin(klass)
-api.finalize()
diff --git a/ipatests/conftest.py b/ipatests/conftest.py
new file mode 100644
index 000..99aaab4
--- /dev/null
+++ b/ipatests/conftest.py
@@ -0,0 +1,59 @@
+#
+# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
+#
+from __future__ import print_function
+
+from ipalib import api
+from ipalib.cli import cli_plugins
+try:
+import ipaserver
+except ImportError:
+ipaserver = None
+
+
+pytest_plugins = [
+'ipatests.pytest_plugins.additional_config',
+'ipatests.pytest_plugins.beakerlib',
+'ipatests.pytest_plugins.declarative',
+'ipatests.pytest_plugins.nose_compat',
+]
+# The integration plugin is not available in client-only builds.
+if ipaserver is not None:
+pytest_plugins.append('ipatests.pytest_plugins.integration')
+
+
+MARKERS = [
+'tier0: basic unit tests and critical functionality',
+'tier1: functional API tests',
+'cs_acceptance: Acceptance test suite for Dogtag Certificate Server',
+'ds_acceptance: Acceptance test suite for 389 Directory Server',
+]
+
+
+NO_RECURSE_DIRS = [
+# build directories
+'ipaclient/build',
+'ipalib/build',
+'ipaplatform/build',
+'ipapython/build',
+'ipaserver/build',
+'ipatests/build',
+# install/share/wsgi.py
+'install/share'
+]
+
+
+def pytest_configure(config):
+for marker in MARKERS:
+config.addinivalue_line('markers', marker)
+for norecursedir in NO_RECURSE_DIRS:
+config.addinivalue_line('norecursedirs', norecursedir)
+
+
+def pytest_cmdline_main(config):
+api.bootstrap(
+context=u'cli', in_server=False, in_tree=True, fallback=False
+)
+for klass in cli_plugins:
+api.add_plugin(klass)
+api.finalize()
diff --git a/ipatests/ipa-run-tests b/ipatests/ipa-run-tests
index 53fa7b3..8df477d 100755
--- a/ipatests/ipa-run-tests
+++ b/ipatests/ipa-run-tests
@@ -34,9 +34,6 @@ import pytest
 
 import ipatests
 
-# This must be set so ipalib.api gets initialized property for tests:
-os.environ['IPA_UNIT_TEST_MODE'] = 'cli_test'
-
 # This is set to store --with-xunit report in an accessible place:
 os.environ['IPATEST_XUNIT_PATH'] = os.path.join(os.getcwd(), 'nosetests.xml')
 
diff --git a/ipatests/pytest.ini b/ipatests/pytest.ini
index c14eb5d..deb8688 100644
--- a/ipatests/pytest.ini
+++ b/ipatests/pytest.ini
@@ -8,16 +8,6 @@
 python_classes = test_ Test
 addopts = --doctest-modules
   --junit-prefix ipa
-  -p ipatests.pytest_plugins.nose_compat
-  -p ipatests.pytest_plugins.declarative
-  -p ipatests.pytest_plugins.integration
-  -p ipatests.pytest_plugins.beakerlib
-  -p ipatests.pytest_plugins.additional_config
 # Ignore files for doc tests.
 # TODO: ideally, these should all use __name__=='__main__' guards
   --ignore=install/share/wsgi.py
-markers =
-tier0: basic unit tests and critical functionality
-tier1: functional API tests
-cs_acceptance: Acceptance test suite for Dogtag Certificate Server
-ds_acceptance: Acceptance test suite for 389 Directory Server
diff --git a/make-test b/make-test
index 76e3dde..93323a1 100755
--- a/make-test
+++ b/make-test
@@ -1,4 +1,4 @@
 #! /bin/bash
 
 set -ex
-IPA_UNIT_TEST_MODE=cli_test PYTHONPATH=.:$PYTHONPATH py.test "$@"
+PYTHONPATH=.:$PYTHONPATH py.test "$@"

From 96c29bddc9111b9c435d435f792e02648efdd6cd Mon Sep 17 00:00:00 2001
From: Christian 

[Freeipa-devel] [freeipa PR#366][synchronized] Use pytest conftest.py

2017-01-04 Thread tiran
   URL: https://github.com/freeipa/freeipa/pull/366
Author: tiran
 Title: #366: Use pytest conftest.py 
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/366/head:pr366
git checkout pr366
From 45011a60f63d5471ccf85cf7549362dd7ad3cb23 Mon Sep 17 00:00:00 2001
From: Christian Heimes 
Date: Tue, 3 Jan 2017 18:04:53 +0100
Subject: [PATCH] Use pytest conftest.py

Let's replace some ugly hacks with proper pytest conftest.py hooks.
Test initialization of ipalib.api is now handled in
pytest_cmdline_main(). Pytest plugins, markers and ignores are also
moved into conftest.py. Additional guards make it possible to run tests
without ipaserver installed.
---
 ipalib/__init__.py |  7 --
 ipatests/conftest.py   | 59 ++
 ipatests/ipa-run-tests |  3 ---
 ipatests/pytest.ini| 10 -
 make-test  |  2 +-
 5 files changed, 60 insertions(+), 21 deletions(-)
 create mode 100644 ipatests/conftest.py

diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index 4a61ace..5a11f86 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -949,10 +949,3 @@ def create_api(mode='dummy'):
 return api
 
 api = create_api(mode=None)
-
-if os.environ.get('IPA_UNIT_TEST_MODE', None) == 'cli_test':
-from ipalib.cli import cli_plugins
-api.bootstrap(context='cli', in_server=False, in_tree=True, fallback=False)
-for klass in cli_plugins:
-api.add_plugin(klass)
-api.finalize()
diff --git a/ipatests/conftest.py b/ipatests/conftest.py
new file mode 100644
index 000..99aaab4
--- /dev/null
+++ b/ipatests/conftest.py
@@ -0,0 +1,59 @@
+#
+# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
+#
+from __future__ import print_function
+
+from ipalib import api
+from ipalib.cli import cli_plugins
+try:
+import ipaserver
+except ImportError:
+ipaserver = None
+
+
+pytest_plugins = [
+'ipatests.pytest_plugins.additional_config',
+'ipatests.pytest_plugins.beakerlib',
+'ipatests.pytest_plugins.declarative',
+'ipatests.pytest_plugins.nose_compat',
+]
+# The integration plugin is not available in client-only builds.
+if ipaserver is not None:
+pytest_plugins.append('ipatests.pytest_plugins.integration')
+
+
+MARKERS = [
+'tier0: basic unit tests and critical functionality',
+'tier1: functional API tests',
+'cs_acceptance: Acceptance test suite for Dogtag Certificate Server',
+'ds_acceptance: Acceptance test suite for 389 Directory Server',
+]
+
+
+NO_RECURSE_DIRS = [
+# build directories
+'ipaclient/build',
+'ipalib/build',
+'ipaplatform/build',
+'ipapython/build',
+'ipaserver/build',
+'ipatests/build',
+# install/share/wsgi.py
+'install/share'
+]
+
+
+def pytest_configure(config):
+for marker in MARKERS:
+config.addinivalue_line('markers', marker)
+for norecursedir in NO_RECURSE_DIRS:
+config.addinivalue_line('norecursedirs', norecursedir)
+
+
+def pytest_cmdline_main(config):
+api.bootstrap(
+context=u'cli', in_server=False, in_tree=True, fallback=False
+)
+for klass in cli_plugins:
+api.add_plugin(klass)
+api.finalize()
diff --git a/ipatests/ipa-run-tests b/ipatests/ipa-run-tests
index 53fa7b3..8df477d 100755
--- a/ipatests/ipa-run-tests
+++ b/ipatests/ipa-run-tests
@@ -34,9 +34,6 @@ import pytest
 
 import ipatests
 
-# This must be set so ipalib.api gets initialized property for tests:
-os.environ['IPA_UNIT_TEST_MODE'] = 'cli_test'
-
 # This is set to store --with-xunit report in an accessible place:
 os.environ['IPATEST_XUNIT_PATH'] = os.path.join(os.getcwd(), 'nosetests.xml')
 
diff --git a/ipatests/pytest.ini b/ipatests/pytest.ini
index c14eb5d..deb8688 100644
--- a/ipatests/pytest.ini
+++ b/ipatests/pytest.ini
@@ -8,16 +8,6 @@
 python_classes = test_ Test
 addopts = --doctest-modules
   --junit-prefix ipa
-  -p ipatests.pytest_plugins.nose_compat
-  -p ipatests.pytest_plugins.declarative
-  -p ipatests.pytest_plugins.integration
-  -p ipatests.pytest_plugins.beakerlib
-  -p ipatests.pytest_plugins.additional_config
 # Ignore files for doc tests.
 # TODO: ideally, these should all use __name__=='__main__' guards
   --ignore=install/share/wsgi.py
-markers =
-tier0: basic unit tests and critical functionality
-tier1: functional API tests
-cs_acceptance: Acceptance test suite for Dogtag Certificate Server
-ds_acceptance: Acceptance test suite for 389 Directory Server
diff --git a/make-test b/make-test
index 76e3dde..93323a1 100755
--- a/make-test
+++ b/make-test
@@ -1,4 +1,4 @@
 #! /bin/bash
 
 set -ex
-IPA_UNIT_TEST_MODE=cli_test PYTHONPATH=.:$PYTHONPATH py.test "$@"
+PYTHONPATH=.:$PYTHONPATH py.test "$@"
-- 
Manage your subscription for the Freeipa-devel mailing list:

[Freeipa-devel] [freeipa PR#366][synchronized] Use pytest conftest.py

2017-01-03 Thread tiran
   URL: https://github.com/freeipa/freeipa/pull/366
Author: tiran
 Title: #366: Use pytest conftest.py 
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/366/head:pr366
git checkout pr366
From 2e56469a7cbbc1de9b3fa24b715ab235adc184d6 Mon Sep 17 00:00:00 2001
From: Christian Heimes 
Date: Tue, 3 Jan 2017 18:04:53 +0100
Subject: [PATCH 1/3] Use pytest conftest.py

Let's replace some ugly hacks with proper pytest conftest.py hooks.
Test initialization of ipalib.api is now handled in
pytest_cmdline_main(). Pytest plugins, markers and ignores are also
moved into conftest.py. Additional guards make it possible to run tests
without ipaserver installed.
---
 ipalib/__init__.py |  6 
 ipatests/conftest.py   | 77 ++
 ipatests/ipa-run-tests |  3 --
 ipatests/pytest.ini| 10 ---
 make-test  |  2 +-
 5 files changed, 78 insertions(+), 20 deletions(-)
 create mode 100644 ipatests/conftest.py

diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index 4a61ace..9cbe528 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -950,9 +950,3 @@ def create_api(mode='dummy'):
 
 api = create_api(mode=None)
 
-if os.environ.get('IPA_UNIT_TEST_MODE', None) == 'cli_test':
-from ipalib.cli import cli_plugins
-api.bootstrap(context='cli', in_server=False, in_tree=True, fallback=False)
-for klass in cli_plugins:
-api.add_plugin(klass)
-api.finalize()
diff --git a/ipatests/conftest.py b/ipatests/conftest.py
new file mode 100644
index 000..0399e2f
--- /dev/null
+++ b/ipatests/conftest.py
@@ -0,0 +1,77 @@
+#
+# Copyright (C) 2016  FreeIPA Contributors see COPYING for license
+#
+
+from __future__ import print_function
+
+from ipalib import api
+from ipalib.cli import cli_plugins
+try:
+import ipaserver
+except ImportError:
+ipaserver = None
+
+
+MARKERS = [
+'tier0: basic unit tests and critical functionality',
+'tier1: functional API tests',
+'cs_acceptance: Acceptance test suite for Dogtag Certificate Server',
+'ds_acceptance: Acceptance test suite for 389 Directory Server',
+]
+
+NO_RECURSE_DIRS = [
+# build directories
+'ipaclient/build',
+'ipalib/build',
+'ipaplatform/build',
+'ipapython/build',
+'ipaserver/build',
+'ipatests/build',
+# install/share/wsgi.py
+'install/share'
+]
+
+pytest_plugins = [
+'ipatests.pytest_plugins.additional_config',
+'ipatests.pytest_plugins.beakerlib',
+'ipatests.pytest_plugins.declarative',
+'ipatests.pytest_plugins.nose_compat',
+]
+
+# The integration plugin is not available in client-only builds.
+try:
+import ipatests.pytest_plugins.integration
+except ImportError:
+if ipaserver is not None:
+raise
+else:
+pytest_plugins.append('ipatests.pytest_plugins.integration')
+
+
+def pytest_configure(config):
+# register an additional marker
+for marker in MARKERS:
+config.addinivalue_line('markers', marker)
+
+for norecursedir in NO_RECURSE_DIRS:
+config.addinivalue_line('norecursedirs', norecursedir)
+
+
+def pytest_cmdline_main(config):
+api.bootstrap(
+context=u'cli',
+in_server=False,
+in_tree=True,
+fallback=False)
+
+for klass in cli_plugins:
+api.add_plugin(klass)
+
+try:
+api.finalize()
+except ImportError as e:
+# ipaclient has no ipaserver
+if ipaserver is not None:
+raise
+else:
+print(e)
diff --git a/ipatests/ipa-run-tests b/ipatests/ipa-run-tests
index 53fa7b3..8df477d 100755
--- a/ipatests/ipa-run-tests
+++ b/ipatests/ipa-run-tests
@@ -34,9 +34,6 @@ import pytest
 
 import ipatests
 
-# This must be set so ipalib.api gets initialized property for tests:
-os.environ['IPA_UNIT_TEST_MODE'] = 'cli_test'
-
 # This is set to store --with-xunit report in an accessible place:
 os.environ['IPATEST_XUNIT_PATH'] = os.path.join(os.getcwd(), 'nosetests.xml')
 
diff --git a/ipatests/pytest.ini b/ipatests/pytest.ini
index c14eb5d..deb8688 100644
--- a/ipatests/pytest.ini
+++ b/ipatests/pytest.ini
@@ -8,16 +8,6 @@
 python_classes = test_ Test
 addopts = --doctest-modules
   --junit-prefix ipa
-  -p ipatests.pytest_plugins.nose_compat
-  -p ipatests.pytest_plugins.declarative
-  -p ipatests.pytest_plugins.integration
-  -p ipatests.pytest_plugins.beakerlib
-  -p ipatests.pytest_plugins.additional_config
 # Ignore files for doc tests.
 # TODO: ideally, these should all use __name__=='__main__' guards
   --ignore=install/share/wsgi.py
-markers =
-tier0: basic unit tests and critical functionality
-tier1: functional API tests
-cs_acceptance: Acceptance test suite for Dogtag Certificate Server
-ds_acceptance: Acceptance test suite for 389 Directory Server
diff --git