Skip to content

Invalid python sys path to directory with tested file on Windows #2673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tamarinvs19 opened this issue Nov 3, 2023 · 0 comments · Fixed by #2674
Closed

Invalid python sys path to directory with tested file on Windows #2673

tamarinvs19 opened this issue Nov 3, 2023 · 0 comments · Fixed by #2674
Assignees
Labels
ctg-bug Issue is a bug lang-python Issue is related to python support

Comments

@tamarinvs19
Copy link
Collaborator

tamarinvs19 commented Nov 3, 2023

Description

UnitTestBot generates tests with invalid sys.path on Windows when "Test sources root" coincides with file under test.

To Reproduce

Steps to reproduce the behavior:

  1. Run a python project in Pycharm
  2. Use plugin to generate tests and set a path to directory with tested file in the field "Test sources root"
  3. Open the generated test

Expected behavior

Valid tests with correct sys paths

Actual behavior

Valid tests with incorrect sys path (sys.path.append(os.path.dirname(__file__) + r'\')). The problem is that python raw-string cannot end in backslash.

Visual proofs (screenshots, logs, images)
Tested function
tested function

UTBot window
utbot ui

sys.path
sys paths

Environment

Windows + specified above "Test sources root"

Solutions

  1. Replace backslash at the end by "\."
  2. Remove backslash at the end
  3. Skip sys.path if it coincides with tested function directory
@tamarinvs19 tamarinvs19 added ctg-bug Issue is a bug lang-python Issue is related to python support labels Nov 3, 2023
@tamarinvs19 tamarinvs19 self-assigned this Nov 3, 2023
@tamarinvs19 tamarinvs19 changed the title Invalid python sys path to current directory on Windows Invalid python sys path to test file directory on Windows Nov 3, 2023
@tamarinvs19 tamarinvs19 changed the title Invalid python sys path to test file directory on Windows Invalid python sys path to directory with tested file on Windows Nov 3, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot Java Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug lang-python Issue is related to python support
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant