Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. QA Tools
  3. Squish
  4. Global Scripts added but error No module named

Global Scripts added but error No module named

Scheduled Pinned Locked Moved Unsolved Squish
6 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qttest123
    wrote on last edited by
    #1

    When run test script at Squish IDE, the application does not launch and error returned:
    Detail ModuleNotFoundError: No module named 'prj_lib' C:\AutotestProject\testscripts\suite_1\tst_case_default\test.py:3

    I have added the C:\prj_lib as Global Scripts, but still error occured.

    in the test.py

    from prj_lib import *
     call function from mod1.py
    

    The project structure:
    all test scripts under:
    C:\AutotestProject\testscripts\suite_1

    the custom python scripts to be called in test script by using from prj_lib import *
    C:\prj_lib\app

    • mod1.py
    1 Reply Last reply
    0
    • L Offline
      L Offline
      LarsS
      wrote on last edited by LarsS
      #2

      @Qttest123
      Hello,

      from x import *
      

      This type of import should only be used in a python console session and never in a script as you will pollute your local namespace.

      Only import the symbols you need with

      from x import y
      

      or use the symbol from the module

      import x
      x.y
      

      If you add the folder itself to the global scripts this would be the same as adding the folder to the Python Searchpath.

      You need to add the parent folder to have the folder be recognized as a module.
      I would recommend moving your module in another folder and not add the C: drive to the global scripts.

      Q 1 Reply Last reply
      0
      • L LarsS

        @Qttest123
        Hello,

        from x import *
        

        This type of import should only be used in a python console session and never in a script as you will pollute your local namespace.

        Only import the symbols you need with

        from x import y
        

        or use the symbol from the module

        import x
        x.y
        

        If you add the folder itself to the global scripts this would be the same as adding the folder to the Python Searchpath.

        You need to add the parent folder to have the folder be recognized as a module.
        I would recommend moving your module in another folder and not add the C: drive to the global scripts.

        Q Offline
        Q Offline
        Qttest123
        wrote on last edited by Qttest123
        #3

        @LarsS said in Global Scripts added but error No module named:

        python console session

        i am not sure what is " python console session "
        I guess the originator wanted to run the squish from command when triggered by Jenkins?

        what is the solution to support both, run console also run from squish ide?

        also I am not sure what is Python Searchpath.
        what is parent folder? and where to add it? in the squish IDE?
        and i dont quite sure what do you mean by moving 'module' in another folder....
        sorry i am completely new to squish, please let me know what is the best practise.

        S 2 Replies Last reply
        0
        • Q Qttest123

          @LarsS said in Global Scripts added but error No module named:

          python console session

          i am not sure what is " python console session "
          I guess the originator wanted to run the squish from command when triggered by Jenkins?

          what is the solution to support both, run console also run from squish ide?

          also I am not sure what is Python Searchpath.
          what is parent folder? and where to add it? in the squish IDE?
          and i dont quite sure what do you mean by moving 'module' in another folder....
          sorry i am completely new to squish, please let me know what is the best practise.

          S Offline
          S Offline
          SylvainA
          wrote on last edited by
          #4

          Hi @Qttest123
          You surely already saw this but we never know ^^ :
          https://doc.qt.io/squish/global-scripts-view.html#ide-the-global-scripts-view
          and this directly made by Froglogic team:
          https://www.youtube.com/watch?v=7aE_OkpJSNY

          The python console session is a command line window where you can script and execute live Python (ex : Cmd).

          The Python SearchPath is where all Python's lib are installed.

          A module is a "library". When you do "import toto" toto is a module. So here last comment is right you should put your external lib in "C:\AutotestProject\shared_lib" for exemple. It's in the section of "best practice" if you want.

          In this exemple "C:\AutotestProject\shared_lib", the folder "shared_lib" will be the parent folder of all you .py lib in it.

          It seems that you are new to Python too. You can also check how to call an external python class to improve your knowledge. Just a simple example will help you.
          https://www.geeksforgeeks.org/python-call-function-from-another-file/

          I hope it will help you.

          Q 1 Reply Last reply
          0
          • Q Qttest123

            @LarsS said in Global Scripts added but error No module named:

            python console session

            i am not sure what is " python console session "
            I guess the originator wanted to run the squish from command when triggered by Jenkins?

            what is the solution to support both, run console also run from squish ide?

            also I am not sure what is Python Searchpath.
            what is parent folder? and where to add it? in the squish IDE?
            and i dont quite sure what do you mean by moving 'module' in another folder....
            sorry i am completely new to squish, please let me know what is the best practise.

            S Offline
            S Offline
            SylvainA
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • S SylvainA

              Hi @Qttest123
              You surely already saw this but we never know ^^ :
              https://doc.qt.io/squish/global-scripts-view.html#ide-the-global-scripts-view
              and this directly made by Froglogic team:
              https://www.youtube.com/watch?v=7aE_OkpJSNY

              The python console session is a command line window where you can script and execute live Python (ex : Cmd).

              The Python SearchPath is where all Python's lib are installed.

              A module is a "library". When you do "import toto" toto is a module. So here last comment is right you should put your external lib in "C:\AutotestProject\shared_lib" for exemple. It's in the section of "best practice" if you want.

              In this exemple "C:\AutotestProject\shared_lib", the folder "shared_lib" will be the parent folder of all you .py lib in it.

              It seems that you are new to Python too. You can also check how to call an external python class to improve your knowledge. Just a simple example will help you.
              https://www.geeksforgeeks.org/python-call-function-from-another-file/

              I hope it will help you.

              Q Offline
              Q Offline
              Qttest123
              wrote on last edited by Qttest123
              #6

              @SylvainA I updated my project structure:
              all test scripts under:
              G:\test\automated_test\AutotestProject3\testscripts

              the custom python scripts to be called in test script by using "from project_lib import *"
              G:\test\automated_test\AutotestProject3\project_lib

              then you commented : So here last comment is right you should put your external lib in "C:\AutotestProject\shared_lib" for example.

              is the "shared_lib" a fixed name and directory that I should use in order to let squish automatically recognize where is the external libraries?

              then what is the usage of "Global Scripts" ? the originator seems thought that it can be used to point the external libraries but in my case it does not work.

              I did not see such problem when using open source test framework and pycharm to point them.
              I guess Squish has special way to do it?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved