From f84d76eb0af5846caa066bff21b62547d1c01e56 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Thu, 20 Oct 2022 12:13:23 +1100 Subject: [PATCH 1/2] Pair all fields in the setup with those used in test_cases incase the test crashes after setup --- pytest_nunit/plugin.py | 4 ++++ setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pytest_nunit/plugin.py b/pytest_nunit/plugin.py index 5a90fb4..b58c7a3 100644 --- a/pytest_nunit/plugin.py +++ b/pytest_nunit/plugin.py @@ -147,9 +147,13 @@ def record_testreport(self, testreport): "error": "", "stack-trace": "", "name": self.nunit_xml.prefix + testreport.nodeid, + "reason": "", + "outcome": "", } self.nunit_xml.idrefindex += 1 # Inc. node id ref counter r["start"] = datetime.utcnow() # Will be overridden if called + r["stop"] = datetime.utcnow() # Will be overridden if called + r["duration"] = 0 # Updated on teardown if testreport.outcome == "skipped": log.debug("skipping : {0}".format(testreport.longrepr)) if ( diff --git a/setup.py b/setup.py index 37ae089..520d66c 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ def getversion(): ], }, classifiers=[ - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', 'Framework :: Pytest', 'Intended Audience :: Developers', 'Topic :: Software Development :: Testing', From 5590294e26f1ee0dfc81b2aa345804f7a4f0ce19 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Thu, 20 Oct 2022 12:34:21 +1100 Subject: [PATCH 2/2] update release notes and resort imports --- CHANGELOG.md | 4 ++++ ext/generate-models.py | 3 ++- pytest_nunit/__init__.py | 2 +- pytest_nunit/attrs2xml.py | 2 +- pytest_nunit/models/nunit.py | 3 ++- pytest_nunit/nunit.py | 33 ++++++++++------------------ pytest_nunit/plugin.py | 15 ++++++------- setup.py | 8 +++---- tests/integration/test_azure.py | 1 + tests/integration/test_config.py | 1 + tests/integration/test_filters.py | 3 ++- tests/integration/test_properties.py | 3 ++- tests/integration/test_report.py | 3 ++- tests/integration/test_schema.py | 3 ++- tests/integration/test_tests.py | 3 ++- 15 files changed, 44 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5541894..ecaf440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.0.3 (20th October 2022) + +* Fixes bug when used with xdist extension by @tonybaloney in https://github.com/pytest-dev/pytest-nunit/pull/66 + ## 1.0.2 (19th October 2022) * Don't assert that call-report exists before checking value of attribute by @tonybaloney in https://github.com/pytest-dev/pytest-nunit/pull/63 diff --git a/ext/generate-models.py b/ext/generate-models.py index e3395fc..850c2a9 100644 --- a/ext/generate-models.py +++ b/ext/generate-models.py @@ -7,10 +7,11 @@ Written by Anthony Shaw. """ +import keyword import logging + import xmlschema import xmlschema.qnames -import keyword try: import black diff --git a/pytest_nunit/__init__.py b/pytest_nunit/__init__.py index 7863915..976498a 100644 --- a/pytest_nunit/__init__.py +++ b/pytest_nunit/__init__.py @@ -1 +1 @@ -__version__ = "1.0.2" +__version__ = "1.0.3" diff --git a/pytest_nunit/attrs2xml.py b/pytest_nunit/attrs2xml.py index cc888a7..692c585 100644 --- a/pytest_nunit/attrs2xml.py +++ b/pytest_nunit/attrs2xml.py @@ -1,6 +1,6 @@ +import enum import xml.etree.ElementTree as ET from xml.sax.saxutils import escape -import enum class CdataComment(ET.Element): diff --git a/pytest_nunit/models/nunit.py b/pytest_nunit/models/nunit.py index efd16a6..fe1f816 100644 --- a/pytest_nunit/models/nunit.py +++ b/pytest_nunit/models/nunit.py @@ -1,6 +1,7 @@ -import attr import enum +import attr + class TestDurationType(float): pass diff --git a/pytest_nunit/nunit.py b/pytest_nunit/nunit.py index 44ed1bb..3488cf2 100644 --- a/pytest_nunit/nunit.py +++ b/pytest_nunit/nunit.py @@ -1,29 +1,18 @@ -import sys -import os +import getpass import locale +import os import platform -import getpass -from .models.nunit import ( - TestRunType, - TestResultType, - TestCaseElementType, - TestSuiteElementType, - TestStatusType, - TestRunStateType, - TestSuiteTypeType, - PropertyBagType, - PropertyType, - EnvironmentType, - AttachmentsType, - AttachmentType, - ReasonType, - FailureType, - TestFilterType, - ValueMatchFilterType, -) -from .attrs2xml import AttrsXmlRenderer, CdataComment +import sys + from _pytest._code.code import ExceptionChainRepr +from .attrs2xml import AttrsXmlRenderer, CdataComment +from .models.nunit import (AttachmentsType, AttachmentType, EnvironmentType, + FailureType, PropertyBagType, PropertyType, + ReasonType, TestCaseElementType, TestFilterType, + TestResultType, TestRunStateType, TestRunType, + TestStatusType, TestSuiteElementType, + TestSuiteTypeType, ValueMatchFilterType) FRAMEWORK_VERSION = "3.6.2" # Nunit version this was based on CLR_VERSION = sys.version diff --git a/pytest_nunit/plugin.py b/pytest_nunit/plugin.py index b58c7a3..d6ca156 100644 --- a/pytest_nunit/plugin.py +++ b/pytest_nunit/plugin.py @@ -5,19 +5,18 @@ Shares the same pattern of CLI options for ease of use. """ -from _pytest.config import filename_arg - -from io import open +import functools +import logging import os import sys +from collections import Counter, defaultdict, namedtuple from datetime import datetime -import functools -from collections import namedtuple, defaultdict, Counter - -from .nunit import NunitTestRun +from io import open -import logging import pytest +from _pytest.config import filename_arg + +from .nunit import NunitTestRun log = logging.getLogger(__name__) diff --git a/setup.py b/setup.py index 520d66c..ed22efb 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import os import codecs -from setuptools import find_packages -from setuptools import setup +import os + +from setuptools import find_packages, setup def read(fname): @@ -16,7 +16,7 @@ def getversion(): if 'BUILD_VERSION' in os.environ: return os.environ['BUILD_VERSION'] else: - return "1.0.2" + return "1.0.3" setup( diff --git a/tests/integration/test_azure.py b/tests/integration/test_azure.py index a1b4e68..37b2b6e 100644 --- a/tests/integration/test_azure.py +++ b/tests/integration/test_azure.py @@ -3,6 +3,7 @@ """ import os + import pytest diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py index ffe6b81..222d751 100644 --- a/tests/integration/test_config.py +++ b/tests/integration/test_config.py @@ -1,4 +1,5 @@ import os + import xmlschema diff --git a/tests/integration/test_filters.py b/tests/integration/test_filters.py index 41d4cf9..22407e0 100644 --- a/tests/integration/test_filters.py +++ b/tests/integration/test_filters.py @@ -1,9 +1,10 @@ """ Test adding properties to tests """ -import xmlschema import os +import xmlschema + def test_keyword_filter(testdir, tmpdir): testdir.makepyfile( diff --git a/tests/integration/test_properties.py b/tests/integration/test_properties.py index 340368e..73e517f 100644 --- a/tests/integration/test_properties.py +++ b/tests/integration/test_properties.py @@ -1,9 +1,10 @@ """ Test adding properties to tests """ -import xmlschema import os +import xmlschema + def test_basic_property(testdir, tmpdir): """ diff --git a/tests/integration/test_report.py b/tests/integration/test_report.py index ffb4c24..daaa201 100644 --- a/tests/integration/test_report.py +++ b/tests/integration/test_report.py @@ -2,9 +2,10 @@ Test conversion of collected results into module reports. """ +from datetime import datetime, timedelta + import pytest -from datetime import datetime, timedelta from pytest_nunit.plugin import NunitXML # This class method takes a dict of node_id->dict representing all the diff --git a/tests/integration/test_schema.py b/tests/integration/test_schema.py index db17a00..b825cbb 100644 --- a/tests/integration/test_schema.py +++ b/tests/integration/test_schema.py @@ -2,9 +2,10 @@ Validate the output XML file against the schema """ import os -import xmlschema from xml.etree import ElementTree +import xmlschema + def test_basic_against_reference_schema(testdir, tmpdir): """ diff --git a/tests/integration/test_tests.py b/tests/integration/test_tests.py index b9b6450..cac4a23 100644 --- a/tests/integration/test_tests.py +++ b/tests/integration/test_tests.py @@ -1,9 +1,10 @@ """ Test various scenarios """ -import xmlschema import os +import xmlschema + def test_passing_test(testdir, tmpdir): """