Skip to content

DYN-8274 PythonScript With Exception#16303

Merged
zeusongit merged 3 commits into
DynamoDS:masterfrom
RobertGlobant20:DYN-8274-PythonScript-WithException-UnitTest
Jun 18, 2025
Merged

DYN-8274 PythonScript With Exception#16303
zeusongit merged 3 commits into
DynamoDS:masterfrom
RobertGlobant20:DYN-8274-PythonScript-WithException-UnitTest

Conversation

@RobertGlobant20

Copy link
Copy Markdown
Contributor

Purpose

I've added a unit test that will be inserting a piece of code in the PythonScript node so a exception will be generated and will be reflected as a warning message in the node.

Declarations

Check these if you believe they are true

  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB
  • This PR introduces new feature code involve network connecting and is tested with no-network mode.

Release Notes

Added unit test for validating that exception is generated when there is an error in the python script

Reviewers

@aparajit-pratap @zeusongit

FYIs

I've added a unit test that will be inserting a piece of code in the PythonScript node so a exception will be generated and will be reflected as a warning message in the node.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-8274

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a unit test to verify that when a PythonScript node in Dynamo throws an exception, it surfaces as a warning on the node.

  • Introduces a new Dynamo graph (withStatementTest.dyn) that writes to and reads from a file using with statements.
  • Adds Test_With_Exception_Python in PythonEditTests.cs, which runs the graph, replaces a line in the script to trigger an exception, and asserts that a warning appears.
  • Imports CoreNodeModels in the test file to reference the Watch node type.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
test/core/python/withStatementTest.dyn New graph defining a PythonScript node and a Watch node connected
test/Libraries/DynamoPythonTests/PythonEditTests.cs New NUnit test to trigger and verify a Python exception warning on node
Comments suppressed due to low confidence (4)

test/Libraries/DynamoPythonTests/PythonEditTests.cs:677

  • Swap the parameters in Assert.AreEqual so the expected value (0) is first and the actual value (pythonNode.NodeInfos.Count) is second to follow NUnit conventions and improve error clarity.
            Assert.AreEqual(pythonNode.NodeInfos.Count, 0);

test/Libraries/DynamoPythonTests/PythonEditTests.cs:687

  • Swap the parameters in Assert.AreEqual so the expected value (1) is first and the actual value (pythonNode.NodeInfos.Count) is second to follow NUnit conventions and improve error clarity.
            Assert.AreEqual(pythonNode.NodeInfos.Count, 1);

test/Libraries/DynamoPythonTests/PythonEditTests.cs:662

  • [nitpick] The variable name line_update is ambiguous; consider renaming to something more descriptive like replacementLine or exceptionTriggerLine.
            var line_update = "vec = Vector.ByCordinates(10,20)";

test/core/python/withStatementTest.dyn:81

  • IsHidden is represented as a string here, but other boolean flags use actual booleans (false). Consider changing this to false for consistency.
      "IsHidden": "False"

Comment thread test/Libraries/DynamoPythonTests/PythonEditTests.cs Outdated
Comment thread test/Libraries/DynamoPythonTests/PythonEditTests.cs Outdated
zeusongit and others added 2 commits June 17, 2025 16:31
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@zeusongit zeusongit merged commit edbc5d1 into DynamoDS:master Jun 18, 2025
26 of 27 checks passed
@aparajit-pratap

Copy link
Copy Markdown
Contributor

@RobertGlobant20, how did this test pass without your changes to PythonNet merged yet? I thought you had merged your PythonNet PR.

@RobertGlobant20

RobertGlobant20 commented Jun 20, 2025

Copy link
Copy Markdown
Contributor Author

@RobertGlobant20, how did this test pass without your changes to PythonNet merged yet? I thought you had merged your PythonNet PR.

Because this test is just validating the exception generated inside the with statement has the right text but is not validating that the object is disposed correctly when using IDispose interface.

This is the one validating that the object is disposed after a exception (that why I need the Python/Python.Runtime.dll)
#16312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants