From b3cb1250d51c0708709ebb2274ed244df1793124 Mon Sep 17 00:00:00 2001 From: Nicolas Ruflin Date: Tue, 28 Nov 2017 23:02:30 +1100 Subject: [PATCH] Make python tests not executables (#5449) (#5726) * Make python tests not executables Turns out that if a `test_*.py` file is executable, nosetests doesn't pick it up, so the tests are not executed on Linux/Mac. This was the case with two files in Filebeat. This adds a `make check` check to look for such files, so this doesn't happen in the future. (cherry picked from commit baa09e86e459f33c7ebdcbc5997d63343af578fe) --- filebeat/tests/system/test_prospector.py | 7 ++----- filebeat/tests/system/test_registrar.py | 5 ----- libbeat/scripts/Makefile | 2 ++ 3 files changed, 4 insertions(+), 10 deletions(-) mode change 100755 => 100644 filebeat/tests/system/test_prospector.py mode change 100755 => 100644 filebeat/tests/system/test_registrar.py diff --git a/filebeat/tests/system/test_prospector.py b/filebeat/tests/system/test_prospector.py old mode 100755 new mode 100644 index f31be9106a7c..11e233dd8412 --- a/filebeat/tests/system/test_prospector.py +++ b/filebeat/tests/system/test_prospector.py @@ -3,6 +3,7 @@ from filebeat import BaseTest import os import time +import unittest from beat.beat import Proc @@ -582,6 +583,7 @@ def test_skip_symlinks(self): # Make sure there is only one entry, means it didn't follow the symlink assert len(data) == 1 + @unittest.skip("Flaky due to race. Opened https://github.com/elastic/beats/issues/5458") def test_harvester_limit(self): """ Test if harvester_limit applies @@ -714,8 +716,3 @@ def test_restart_recursive_glob(self): name="output contains 'entry2'") filebeat.check_kill_and_wait() - - -if __name__ == '__main__': - import unittest - unittest.main() diff --git a/filebeat/tests/system/test_registrar.py b/filebeat/tests/system/test_registrar.py old mode 100755 new mode 100644 index d96a89239c11..0d8811f1cce0 --- a/filebeat/tests/system/test_registrar.py +++ b/filebeat/tests/system/test_registrar.py @@ -1384,8 +1384,3 @@ def test_registrar_files_with_prospector_level_processors(self): "inode": stat.st_ino, "device": stat.st_dev, }, file_state_os) - - -if __name__ == '__main__': - import unittest - unittest.main() diff --git a/libbeat/scripts/Makefile b/libbeat/scripts/Makefile index cf2b0b725007..a43c42dee7a2 100755 --- a/libbeat/scripts/Makefile +++ b/libbeat/scripts/Makefile @@ -61,6 +61,7 @@ BUILDID?=$(shell git rev-parse HEAD) ## @Building The build ID VIRTUALENV_PARAMS?= INTEGRATION_TESTS?= FIND=. ${PYTHON_ENV}/bin/activate; find . -type f -not -path "*/vendor/*" -not -path "*/build/*" -not -path "*/.git/*" +PERM_EXEC=$(shell [ `uname -s` = "Darwin" ] && echo "+111" || echo "/a+x") # Cross compiling targets CGO?=true ## @building if true, Build with C Go support @@ -104,6 +105,7 @@ check: python-env ## @build Checks project and source code if everything is acco @go get $(GOIMPORTS_REPO) @goimports -local ${GOIMPORTS_LOCAL_PREFIX} -l ${GOFILES_NOVENDOR} | (! grep . -q) || (echo "Code differs from goimports' style" && false) @${FIND} -name *.py -exec autopep8 -d --max-line-length 120 {} \; | (! grep . -q) || (echo "Code differs from autopep8's style" && false) + @${FIND} -wholename "*tests/system/test_*.py" -perm ${PERM_EXEC} -exec false {} + || (echo "Python test files shouldn't be executable, otherwise nose doesn't find them" && false) .PHONY: fmt fmt: python-env ## @build Runs `goimports -l -w` and `autopep8`on the project's source code, modifying any files that do not match its style.