-
Notifications
You must be signed in to change notification settings - Fork 908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test Reorganization #1126
Test Reorganization #1126
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! This has been bothering me since forever 🙂
Given how large util.py is (which is its own problem), I think I'm ok with one giant test_util.py file. Ideally they'd both be smaller, but arbitrarily splitting the tests seems like it'd just create more confusion with no real benefit other than to avoid large files.
Standardize names and locations of tests already in tests/unittests/
test_datasource -> sources
test_distros -> distros
test_vmware -> sources/vmware
test_handler -> config
Big +1
test_runs -> runs # I don't understand fully what these tests are testing
Yeah, I don't think they're named very well. They're basically higher level tests of cloudinit/stages.py . Almost like a super mocked integration test. I think runs
is fine.
Can we use MockDistro
instead of DistroTester
? DistroTester makes me think it would do something to test distros, but it acts as a standin distro for tests that require a distro being passed but don't actually do anything to test the distro.
+1 to everything else you've changed/proposed.
Let's try to get this merged ASAP so you can avoid rebase hell.
Ack
Of course, thanks!
Agreed. Thanks for the review @TheRealFalcon! |
2ca1f3d
to
de09a6e
Compare
@TheRealFalcon In addition to your requested changes, I pushed a change that standardizes the config module testfile names. While doing that I found a couple more duplicate test files and merged them together. @blackboxsw Do you want to take a look at this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your consolidation here under the premise that more frequent than not folks are trying to find code and seek out call sites in functional logic. We, upstream, never got around to pushing all tests to a module-relative ./tests subdirectory fully before the motivation on my side was not strong enough to make that move permanent.
The original concern we were trying to address was what you have remedied here with your directory renames:
tests/unittests subdirectory names didn't represent the same directory structure we see in the code itself. So, folks were confused in which test module to add unit tests.
One we we could have solved this was to mandate module-relative tests, but properly restructuring the directories and test names under tests/unittests is probably more valuable to reduce complexity in development, testing and packaging as well.
Some things I think we can add to this PR:
- git rm tests/unittests/test_handler tests/unittests/test_datasource/ tests/unittests/test_vmware tests/unittests/test_filters tests/unittests/test_distros tests/unittests/test_runs
- Update doc/rtd/topics/testing.rst to redact anything talking about module-local tests subdirectory and point people to tests/unittests
Git doesn't track directories, so I don't think there's anything else to do here. On my machine, I don't see those directories left. Do you? |
Oopsie, I had stale pycache files from an unrelated checkout which left my empty subdirectories intact. A couple of additional comments I think now that all tests out of cloudinit module subdirs:
Also if we are touching tox.ini we could drop the old Xenial support directives. diff --git a/setup.py b/setup.py
index 58fddf0f..1ee9bf0d 100755
--- a/setup.py
+++ b/setup.py
@@ -291,7 +291,7 @@ setuptools.setup(
author='Scott Moser',
author_email='scott.moser@canonical.com',
url='http://launchpad.net/cloud-init/',
- packages=setuptools.find_packages(exclude=['tests.*', '*.tests', 'tests']),
+ packages=setuptools.find_packages(]),
scripts=['tools/cloud-init-per'],
license='Dual-licensed under GPLv3 or Apache 2.0',
data_files=data_files,
diff --git a/tox.ini b/tox.ini
index 874d3f20..3337763d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,7 +3,7 @@ envlist = py3, xenial-dev, flake8, pylint
recreate = True
[testenv]
-commands = {envpython} -m pytest {posargs:tests/unittests cloudinit}
+commands = {envpython} -m pytest {posargs:tests/unittests}
setenv =
LC_ALL = en_US.utf-8
passenv=
@@ -37,7 +37,7 @@ deps =
commands = {envpython} -m pytest \
--durations 10 \
{posargs:--cov=cloudinit --cov-branch \
- tests/unittests cloudinit}
+ tests/unittests}
[testenv:py27]
basepython = python2.7
@@ -162,9 +162,8 @@ setenv =
PYTEST_ADDOPTS="-m not adhoc"
[pytest]
-# TODO: s/--strict/--strict-markers/ once xenial support is dropped
-testpaths = cloudinit tests/unittests
-addopts = --strict
+testpaths = tests/unittests
+addopts = --strict-markers
log_format = %(asctime)s %(levelname)-9s %(name)s:%(filename)s:%(lineno)d %(message)s
log_date_format = %Y-%m-%d %H:%M:%S
markers = |
IIRC we left the Xenial references in tox because it was the easiest way to test 3.5 support. Let's leave that reference until we officially drop 3.5, but +1 to all of Chad's other comments. |
We still need at least Per the setuptools website :
also compare without an exclude list:
versus with tests.* and tests:
The first contains various |
Change directory names under tests/unittests to match directory names in the source tree. test_datasource -> sources test_distros -> distros test_vmware -> sources/vmware test_handler -> config # this contains cloudconfig module tests test_runs -> runs # I don't understand fully what these tests # are testing, but the test_ name is # unnecessary
Also rename a class used for testing to silence some unwanted pytest warnings.
cloudinit/sources/helpers/tests -> tests/unittests/sources/helpers cloudinit/sources/tests -> tests/unittests/sources
cloudinit/cmd/devel/tests -> tests/unittests/cmd/devel cloudinit/cmd/tests -> tests/unittests/cmd/
Patching subp is failing for these tests - successful when pytest is executed individually against this test, but when run against all the tests it fails. This test validates the same logic but mocks the function that calls subp instead. It might be test_util.py that is not cleaning up correctly, but I can't say for certain. (test_util.py might be the culprit?)
One caveat: there are two different files named test_util.py - both over 1K LOC each. Merging doesn't appear straightforward (some tests begin to fail), so I want to get feedback about prefered approach for large files before moving forward. For now they are renamed test_util{1,2}.py and sit under tests/unittests/util/
Modify import paths for all files importing helpers.py
e83117b
to
1d68680
Compare
- Add comment to doc/rtd/topics/testing.rst about test location - Remove filter for packages named `*.tests`, since they no longer exist - Remove cloudinit/ from tox config file; tests no longer live there
1d68680
to
d27caa3
Compare
+1 from me. I think we just need a final approval from @blackboxsw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the cleanup and correcting my assumptions on setup.py. Validated the final deb created continues to avoid packaging tests dirs and test runner continues to hit all tests appropriately.
LGTM!
@blackboxsw @TheRealFalcon - Big thanks to you both for the reviews and support on this! |
Proposed Commit Message
More notes/context
sed
/awk
/find -exec
/etc was used to generate this PRChecklist: