Skip to content

Commit

Permalink
Use MODULE in metricbeat python system tests (#19434) (#19643)
Browse files Browse the repository at this point in the history
`MODULE` can be used with `mage pythonIntegTest` to run python
integration tests for a single module.

(cherry picked from commit 723ad9b)
  • Loading branch information
jsoriano committed Jul 6, 2020
1 parent 896c44b commit 238588a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
21 changes: 20 additions & 1 deletion dev-tools/mage/pytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func init() {
type PythonTestArgs struct {
TestName string // Test name used in logging.
Env map[string]string // Env vars to add to the current env.
Files []string // Globs used by nosetests to find tests.
XUnitReportFile string // File to write the XUnit XML test report to.
CoverageProfileFile string // Test coverage profile file.
}
Expand Down Expand Up @@ -142,7 +143,11 @@ func PythonNoseTest(params PythonTestArgs) error {
)
}

testFiles, err := FindFiles(nosetestsTestFiles...)
files := nosetestsTestFiles
if len(params.Files) > 0 {
files = params.Files
}
testFiles, err := FindFiles(files...)
if err != nil {
return err
}
Expand All @@ -167,6 +172,20 @@ func PythonNoseTest(params PythonTestArgs) error {
// and HTML report.
}

// PythonNoseTestForModule executes python system tests for modules.
//
// Use `MODULE=module` to run only tests for `module`.
func PythonNoseTestForModule(params PythonTestArgs) error {
if module := EnvOr("MODULE", ""); module != "" {
params.Files = []string{
fmt.Sprintf("module/%s/test_*.py", module),
fmt.Sprintf("module/%s/*/test_*.py", module),
}
params.TestName += "-" + module
}
return PythonNoseTest(params)
}

// PythonVirtualenv constructs a virtualenv that contains the given modules as
// defined in the requirements file pointed to by requirementsTxt. It returns
// the path to the virutalenv.
Expand Down
22 changes: 10 additions & 12 deletions docs/devguide/metricset-details.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,22 @@ func TestData(t *testing.T) {
===== Running the Tests

To run all the tests, run `make testsuite`. To only run unit tests, run
`make unit-tests` or for integration tests `make integration-tests-environment`. Be aware that
a running Docker environment is needed for integration and system tests.
`mage unitTest`, or for integration tests `mage integTest`.
Be aware that a running Docker environment is needed for integration and system
tests.

To run `TestData` and generate the `data.json` file, run
`go test -tags=integration -data -run TestData` in the directory where your test is located.

Sometimes you may want to run a single integration test, for example, to test a
module such as the `apache` module. To do this, you can:

. Start the Docker service by running
`docker-compose run -p port:port apache`. You can skip this step if, like the
`golang` module, your module doesn't need a Docker service.
To run the integration tests for a single module, set the `MODULE` environment
variable to the name of the directory of the module. For example you can run the
following command to run integration tests for `apache` module:

. Run `cd tests/system` to change to the folder that contains the integration
tests.
[source,shell]
----
MODULE=apache mage integTest
----

. Run `INTEGRATION_TESTS=true nosetests test_apache.py`,
remembering to replace `test_apache.py` with your own test file.

[float]
=== Documentation
Expand Down
3 changes: 2 additions & 1 deletion metricbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func GoIntegTest(ctx context.Context) error {

// PythonIntegTest executes the python system tests in the integration
// environment (Docker).
// Use MODULE=module to run only tests for `module`.
// Use NOSE_TESTMATCH=pattern to only run tests matching the specified pattern.
// Use any other NOSE_* environment variable to influence the behavior of
// nosetests.
Expand All @@ -203,6 +204,6 @@ func PythonIntegTest(ctx context.Context) error {
}
return runner.Test("pythonIntegTest", func() error {
mg.Deps(devtools.BuildSystemTestBinary)
return devtools.PythonNoseTest(devtools.DefaultPythonTestIntegrationArgs())
return devtools.PythonNoseTestForModule(devtools.DefaultPythonTestIntegrationArgs())
})
}
3 changes: 2 additions & 1 deletion x-pack/metricbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func GoIntegTest(ctx context.Context) error {

// PythonIntegTest executes the python system tests in the integration
// environment (Docker).
// Use MODULE=module to run only tests for `module`.
// Use NOSE_TESTMATCH=pattern to only run tests matching the specified pattern.
// Use any other NOSE_* environment variable to influence the behavior of
// nosetests.
Expand All @@ -158,6 +159,6 @@ func PythonIntegTest(ctx context.Context) error {
}
return runner.Test("pythonIntegTest", func() error {
mg.Deps(devtools.BuildSystemTestBinary)
return devtools.PythonNoseTest(devtools.DefaultPythonTestIntegrationArgs())
return devtools.PythonNoseTestForModule(devtools.DefaultPythonTestIntegrationArgs())
})
}

0 comments on commit 238588a

Please sign in to comment.