Unable to run python tests - No module named beat.beat

I am unable to run python tests for packetbeat or any other beats.
Here's what I've done:

  1. in the packetbeat dir i ran make python-dev
  2. then navigated to the tests/system folder and ran nosetests -x -v. Getting the following error:
❯ nosetests -x -v
Failure: ImportError (No module named beat.beat) ... ERROR

======================================================================
ERROR: Failure: ImportError (No module named beat.beat)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home//Projects/beats/packetbeat/tests/system/test_0001_mysql_spaces.py", line 1, in <module>
    from packetbeat import BaseTest
  File "/home//Projects/beats/packetbeat/tests/system/packetbeat.py", line 5, in <module>
    from beat.beat import TestCase
ImportError: No module named beat.beat

In addition to that python code navigation does not work in either intellij or vscode for same reason:

❯ /home//Projects/beats/packetbeat/build/python-env/bin/python3 /home//Projects/beats/packetbeat/tests/system/test_0005_mysql_integration.py
Traceback (most recent call last):
  File "/home//Projects/beats/packetbeat/tests/system/test_0005_mysql_integration.py", line 1, in <module>
    from packetbeat import BaseTest
  File "/home//Projects/beats/packetbeat/tests/system/packetbeat.py", line 5, in <module>
    from beat.beat import TestCase
ModuleNotFoundError: No module named 'beat'

Beats is not using nosetests anymore. We have adopted pytest instead.

This is how I usually run tests:

python3 -m pytest tests/system/test_base.py --verbose

Let me know if you still have issues.

Hi

Thanks.

Now getting a different error -

FileNotFoundError: [Errno 2] No such file or directory: '/home//Projects/beats/packetbeat/packetbeat.test'

/usr/lib/python3.8/subprocess.py:1702: FileNotFoundError
===================================================== short test summary info =====================================================
FAILED tests/system/test_base.py::Test::test_export_config - FileNotFoundError: [Errno 2] No such file or directory: '/home/dmit...
FAILED tests/system/test_base.py::Test::test_export_ilm_policy - FileNotFoundError: [Errno 2] No such file or directory: '/home/...
FAILED tests/system/test_base.py::Test::test_export_index_pattern - FileNotFoundError: [Errno 2] No such file or directory: '/ho...
FAILED tests/system/test_base.py::Test::test_export_index_pattern_migration - FileNotFoundError: [Errno 2] No such file or direc...
FAILED tests/system/test_base.py::Test::test_export_template - FileNotFoundError: [Errno 2] No such file or directory: '/home/...
=========================================

Ran go test -c and it created packetbeat.test. Would be nice to have all of this in the documentation :frowning:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.