Merge pull request #1640 from mandiant/fix/issue-1592

tests: make fixtures available via conftest.py
This commit is contained in:
Willi Ballenthin
2023-07-13 15:39:11 +02:00
committed by GitHub
14 changed files with 25 additions and 53 deletions

18
.github/ruff.toml vendored
View File

@@ -41,21 +41,3 @@ exclude = [
"*_pb2.py",
"*_pb2.pyi"
]
[per-file-ignores]
# until we address #1592 and move test fixtures into conftest.py
# then we need to ignore imports done to enable pytest fixtures.
#
# F401: `foo` imported but unused
# F811 Redefinition of unused `foo`
"tests/test_main.py" = ["F401", "F811"]
"tests/test_proto.py" = ["F401", "F811"]
"tests/test_freeze.py" = ["F401", "F811"]
"tests/test_function_id.py" = ["F401", "F811"]
"tests/test_viv_features.py" = ["F401", "F811"]
"tests/test_binja_features.py" = ["F401", "F811"]
"tests/test_pefile_features.py" = ["F401", "F811"]
"tests/test_dnfile_features.py" = ["F401", "F811"]
"tests/test_dotnet_features.py" = ["F401", "F811"]
"tests/test_result_document.py" = ["F401", "F811"]
"tests/test_dotnetfile_features.py" = ["F401", "F811"]

View File

@@ -66,6 +66,7 @@
### Development
- update ATT&CK/MBC data for linting #1568 @mr-tz
- log time taken to analyze each function #1290 @williballenthin
- tests: make fixture available via conftest.py #1592 @williballenthin
### Raw diffs
- [capa v5.1.0...master](https://github.com/mandiant/capa/compare/v5.1.0...master)

20
tests/conftest.py Normal file
View File

@@ -0,0 +1,20 @@
# Copyright (C) 2023 Mandiant, Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at: [package root]/LICENSE.txt
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
# import all the symbols from our fixtures
# and make available to test cases, implicitly.
# this is thanks to pytest magic.
#
# see the following for a discussion:
# https://www.revsys.com/tidbits/pytest-fixtures-are-magic/
# https://lobste.rs/s/j8xgym/pytest_fixtures_are_magic
from fixtures import * # noqa: F403 [unable to detect undefined names]
from fixtures import _692f_dotnetfile_extractor # noqa: F401 [imported but unused]
from fixtures import _1c444_dotnetfile_extractor # noqa: F401 [imported but unused]
from fixtures import _039a6_dotnetfile_extractor # noqa: F401 [imported but unused]
from fixtures import _0953c_dotnetfile_extractor # noqa: F401 [imported but unused]

View File

@@ -5,13 +5,11 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
import os
import logging
from pathlib import Path
import pytest
import fixtures
from fixtures import scope, sample
import capa.main

View File

@@ -5,9 +5,7 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
import fixtures
from fixtures import scope, sample
@fixtures.parametrize(

View File

@@ -5,9 +5,7 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
import fixtures
from fixtures import scope, sample, b9f5b_dotnetfile_extractor, mixed_mode_64_dotnetfile_extractor
@fixtures.parametrize(

View File

@@ -5,23 +5,15 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
import pytest
import fixtures
from fixtures import (
FEATURE_PRESENCE_TESTS_DOTNET,
scope,
sample,
b9f5b_dotnetfile_extractor,
mixed_mode_64_dotnetfile_extractor,
)
import capa.features.file
@fixtures.parametrize(
"sample,scope,feature,expected",
FEATURE_PRESENCE_TESTS_DOTNET,
fixtures.FEATURE_PRESENCE_TESTS_DOTNET,
indirect=["sample", "scope"],
)
def test_dotnetfile_features(sample, scope, feature, expected):

View File

@@ -10,7 +10,6 @@ from typing import List
from pathlib import Path
import pytest
from fixtures import z9324d_extractor
import capa.main
import capa.rules

View File

@@ -5,7 +5,7 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
from fixtures import get_function, pma16_01_extractor, extract_function_features
import fixtures
import capa.features.insn
@@ -29,6 +29,6 @@ def test_function_id_complex_match(pma16_01_extractor):
def test_function_id_api_feature(pma16_01_extractor):
f = get_function(pma16_01_extractor, 0x404548)
features = extract_function_features(pma16_01_extractor, f)
f = fixtures.get_function(pma16_01_extractor, 0x404548)
features = fixtures.extract_function_features(pma16_01_extractor, f)
assert capa.features.insn.API("__aulldiv") in features

View File

@@ -10,16 +10,6 @@ import json
import textwrap
import fixtures
from fixtures import (
z499c2_extractor,
z9324d_extractor,
pma16_01_extractor,
pingtaest_extractor,
_692f_dotnetfile_extractor,
_1c444_dotnetfile_extractor,
_039a6_dotnetfile_extractor,
_0953c_dotnetfile_extractor,
)
import capa.main
import capa.rules

View File

@@ -5,11 +5,8 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
from pathlib import PosixPath
import pytest
import fixtures
from fixtures import scope, sample
import capa.features.file

View File

@@ -9,7 +9,6 @@ import copy
from typing import Any
import pytest
from fixtures import a3f3bbc_rd, a076114_rd, pma0101_rd, al_khaserx64_rd, al_khaserx86_rd, dotnet_1c444e_rd
import capa.rules
import capa.render

View File

@@ -9,7 +9,6 @@ import copy
import pytest
import fixtures
from fixtures import a3f3bbc_rd, a076114_rd, pma0101_rd, al_khaserx64_rd, al_khaserx86_rd, dotnet_1c444e_rd
import capa
import capa.engine as ceng

View File

@@ -6,7 +6,6 @@
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
import fixtures
from fixtures import scope, sample
@fixtures.parametrize(