tests: make fixtures available via conftest.py

closes #1592
This commit is contained in:
Willi Ballenthin
2023-07-13 09:37:39 +02:00
parent 8c9853ad12
commit b9090b86ce
13 changed files with 20 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"]

16
tests/conftest.py Normal file
View File

@@ -0,0 +1,16 @@
# 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]

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(