target/strelka

Usage of __file__ Throwing Warnings

Closed this issue · 2 comments

Describe the bug

Tests use the __file__ variable, easy_install does not like.

Steps to reproduce

docker-compose build

...

strelka.tests.__pycache__.test_scan_docx.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_gif.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_html.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_iso.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_jpeg.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_msi.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_pe.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_png_eof.cpython-310: module references __file__
strelka.tests.__pycache__.test_scan_vhd.cpython-310: module references __file__

...

Expected behavior

Tests should not throw warnings.

Screenshots
N/A

Release

  • Release: 0.22.12.08

Additional context

__file__ is a global variable that contains the name of the file in which it is used. This warning is probably because using a reference like that may lead to import issues.

To avoid this warning, we can try to remove any references and replace with the __name__ attribute instead, as this attribute contains the name of the module rather than the file path.

For example:
https://github.com/target/strelka/blob/master/src/python/strelka/tests/test_scan_bzip2.py#L19, would change __file__ to __name__, using the name of the module rather than the file path.

Not sure that will work in this context, but I will give this a test in the near future.

The above method could work, but would require refactoring. In the application's current state and based on how Strelka is built, this will warning will not cause issues.

The following PR was submitted to silence this warning: #272 (comment)