pytest, any way to include a test file or list of test files?Can't get pytest to understand command-line arguments on setupsunittest Vs pytestIn pytest, what is the use of conftest.py files?Creating a testing infrastructure with Pytest , Selenium Grid and DockerIs there a way to specify which pytest tests to run from a file?Chain multiple fixtures pytest/unittest hybridHow should I structure a pytest test only package?Pytest webdriver fixture can't introspect some optionsPyTest not discovering new test module, but changes made in old test modules are reflected in executionWhat is a correct approach to manage test data using pytest?

Bb13b9 confusion

How can I make 12 tone and atonal melodies sound interesting?

Extreme flexible working hours: how to get to know people and activities?

Is it possible to fly backward if you have REALLY STRONG headwind?

Why is there always a fire truck present before refuelling?

Proving that a Russian cryptographic standard is too structured

Are there any normal animals in Pokemon universe?

Getting UPS Power from One Room to Another

Is it safe to change the harddrive power feature so that it never turns off?

Scientist couple raises alien baby

Electricity free spaceship

Origin of "boor"

Specific use case of to_address

Whats the meaning of enp#s#f#?

Why did Intel abandon unified CPU cache?

What is the color of artificial intelligence?

What are neighboring ports?

Longest bridge/tunnel that can be cycled over/through?

What does 思ってやっている mean?

What are some really overused phrases in French that are common nowadays?

How to hide rifle during medieval town entrance inspection?

Is it possible to have a wealthy country without a middle class?

Non-aqueous eyes?

With Ubuntu 18.04, how can I have a hot corner that locks the computer?



pytest, any way to include a test file or list of test files?


Can't get pytest to understand command-line arguments on setupsunittest Vs pytestIn pytest, what is the use of conftest.py files?Creating a testing infrastructure with Pytest , Selenium Grid and DockerIs there a way to specify which pytest tests to run from a file?Chain multiple fixtures pytest/unittest hybridHow should I structure a pytest test only package?Pytest webdriver fixture can't introspect some optionsPyTest not discovering new test module, but changes made in old test modules are reflected in executionWhat is a correct approach to manage test data using pytest?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am looking for best practices advices regarding the following context:



  • I am using pytest to run integration tests on my IAC deployment

  • My IAC code base is structured as:

 myapp
|
|_roles
| |_role1
| |_role2
|_resources
|_tomcat
|_java


I'd like to use the same kind of structure for my test files.
Tests are currently divided in file matching roles (role1, role2):



 tests
|
|_roles
|_test_role1.py
|_test_role2.py



which lead to duplicated code, e.g:



  • role1 is a tomcat base app,


  • role2 holds pure java code,


So in both test files (test_role1.py and test_role2.py) there will be a java test function.



If I could add a dir structure as:



 tests
|
|_roles
| |_test_role1.py
| |_test_role2.py
|
|_resources
|_test_tomcat.py
|_test_java.py



Then I could just "include / import" the test_java.py functions to use them in test_role1.py and test_role2.py without duplicating code...



What's the best way to achieve this ?



I am already using fixtures (defined in conftest.py), and I feel that the solution to my duplicated code is something along fixture or test modules but my poor python / pytest knowledge is keeping me away from the actual solution.



Thanks










share|improve this question




























    0















    I am looking for best practices advices regarding the following context:



    • I am using pytest to run integration tests on my IAC deployment

    • My IAC code base is structured as:

     myapp
    |
    |_roles
    | |_role1
    | |_role2
    |_resources
    |_tomcat
    |_java


    I'd like to use the same kind of structure for my test files.
    Tests are currently divided in file matching roles (role1, role2):



     tests
    |
    |_roles
    |_test_role1.py
    |_test_role2.py



    which lead to duplicated code, e.g:



    • role1 is a tomcat base app,


    • role2 holds pure java code,


    So in both test files (test_role1.py and test_role2.py) there will be a java test function.



    If I could add a dir structure as:



     tests
    |
    |_roles
    | |_test_role1.py
    | |_test_role2.py
    |
    |_resources
    |_test_tomcat.py
    |_test_java.py



    Then I could just "include / import" the test_java.py functions to use them in test_role1.py and test_role2.py without duplicating code...



    What's the best way to achieve this ?



    I am already using fixtures (defined in conftest.py), and I feel that the solution to my duplicated code is something along fixture or test modules but my poor python / pytest knowledge is keeping me away from the actual solution.



    Thanks










    share|improve this question
























      0












      0








      0








      I am looking for best practices advices regarding the following context:



      • I am using pytest to run integration tests on my IAC deployment

      • My IAC code base is structured as:

       myapp
      |
      |_roles
      | |_role1
      | |_role2
      |_resources
      |_tomcat
      |_java


      I'd like to use the same kind of structure for my test files.
      Tests are currently divided in file matching roles (role1, role2):



       tests
      |
      |_roles
      |_test_role1.py
      |_test_role2.py



      which lead to duplicated code, e.g:



      • role1 is a tomcat base app,


      • role2 holds pure java code,


      So in both test files (test_role1.py and test_role2.py) there will be a java test function.



      If I could add a dir structure as:



       tests
      |
      |_roles
      | |_test_role1.py
      | |_test_role2.py
      |
      |_resources
      |_test_tomcat.py
      |_test_java.py



      Then I could just "include / import" the test_java.py functions to use them in test_role1.py and test_role2.py without duplicating code...



      What's the best way to achieve this ?



      I am already using fixtures (defined in conftest.py), and I feel that the solution to my duplicated code is something along fixture or test modules but my poor python / pytest knowledge is keeping me away from the actual solution.



      Thanks










      share|improve this question














      I am looking for best practices advices regarding the following context:



      • I am using pytest to run integration tests on my IAC deployment

      • My IAC code base is structured as:

       myapp
      |
      |_roles
      | |_role1
      | |_role2
      |_resources
      |_tomcat
      |_java


      I'd like to use the same kind of structure for my test files.
      Tests are currently divided in file matching roles (role1, role2):



       tests
      |
      |_roles
      |_test_role1.py
      |_test_role2.py



      which lead to duplicated code, e.g:



      • role1 is a tomcat base app,


      • role2 holds pure java code,


      So in both test files (test_role1.py and test_role2.py) there will be a java test function.



      If I could add a dir structure as:



       tests
      |
      |_roles
      | |_test_role1.py
      | |_test_role2.py
      |
      |_resources
      |_test_tomcat.py
      |_test_java.py



      Then I could just "include / import" the test_java.py functions to use them in test_role1.py and test_role2.py without duplicating code...



      What's the best way to achieve this ?



      I am already using fixtures (defined in conftest.py), and I feel that the solution to my duplicated code is something along fixture or test modules but my poor python / pytest knowledge is keeping me away from the actual solution.



      Thanks







      module pytest fixtures






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 19:26









      PierPier

      1131313




      1131313






















          1 Answer
          1






          active

          oldest

          votes


















          0














          If you don't mind running your tests as a module, you could turn your Python files into packages by placing a file called 'init.py' in the root of the project, in the directory with the code to be tested and in the directory with the testing code.



          You can then perform relative imports to access the functions you need:
          eg to access "_test_java.py" from "_test_role2.py"



          from ../_roles import _test_java


          A single dot represent the current directory. Two dots represents the parent directory.



          You will need to use the -m flag when calling your code so Python understands you are running a module with relative imports.



          In your case you might consider performing the messy relative imports in conftest.py



          This post explains the above in more detail:
          http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327657%2fpytest-any-way-to-include-a-test-file-or-list-of-test-files%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            If you don't mind running your tests as a module, you could turn your Python files into packages by placing a file called 'init.py' in the root of the project, in the directory with the code to be tested and in the directory with the testing code.



            You can then perform relative imports to access the functions you need:
            eg to access "_test_java.py" from "_test_role2.py"



            from ../_roles import _test_java


            A single dot represent the current directory. Two dots represents the parent directory.



            You will need to use the -m flag when calling your code so Python understands you are running a module with relative imports.



            In your case you might consider performing the messy relative imports in conftest.py



            This post explains the above in more detail:
            http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/






            share|improve this answer



























              0














              If you don't mind running your tests as a module, you could turn your Python files into packages by placing a file called 'init.py' in the root of the project, in the directory with the code to be tested and in the directory with the testing code.



              You can then perform relative imports to access the functions you need:
              eg to access "_test_java.py" from "_test_role2.py"



              from ../_roles import _test_java


              A single dot represent the current directory. Two dots represents the parent directory.



              You will need to use the -m flag when calling your code so Python understands you are running a module with relative imports.



              In your case you might consider performing the messy relative imports in conftest.py



              This post explains the above in more detail:
              http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/






              share|improve this answer

























                0












                0








                0







                If you don't mind running your tests as a module, you could turn your Python files into packages by placing a file called 'init.py' in the root of the project, in the directory with the code to be tested and in the directory with the testing code.



                You can then perform relative imports to access the functions you need:
                eg to access "_test_java.py" from "_test_role2.py"



                from ../_roles import _test_java


                A single dot represent the current directory. Two dots represents the parent directory.



                You will need to use the -m flag when calling your code so Python understands you are running a module with relative imports.



                In your case you might consider performing the messy relative imports in conftest.py



                This post explains the above in more detail:
                http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/






                share|improve this answer













                If you don't mind running your tests as a module, you could turn your Python files into packages by placing a file called 'init.py' in the root of the project, in the directory with the code to be tested and in the directory with the testing code.



                You can then perform relative imports to access the functions you need:
                eg to access "_test_java.py" from "_test_role2.py"



                from ../_roles import _test_java


                A single dot represent the current directory. Two dots represents the parent directory.



                You will need to use the -m flag when calling your code so Python understands you are running a module with relative imports.



                In your case you might consider performing the messy relative imports in conftest.py



                This post explains the above in more detail:
                http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 3 at 19:13









                theObservertheObserver

                829




                829





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327657%2fpytest-any-way-to-include-a-test-file-or-list-of-test-files%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해