Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:07:16+00:00 2026-06-04T10:07:16+00:00

I have written a package ( http://github.com/anntzer/parsedcmd ) that runs with both Python2 and

  • 0

I have written a package (http://github.com/anntzer/parsedcmd) that runs with both Python2 and Python3. However, I had to write separate (py.test) unit tests for Python2 and Python3 (mainly because I want to test extra features of Python3, in particular keyword-only arguments), so I have a test_py2.py and a test_py3.py in a test subpackage. Now, if I run, say py.test2 mypkg, test_py2 passes, but test_py3 fails with a SyntaxError. Likewise, for py.test3 mypkg, test_py3 passes but test_py2 fails (I could make this one work though, it’s just an issue of StringIO having moved to io).

I can design the test subpackage so that import mypkg.test only imports the proper version of the tests, but apparently py.test doesn’t care — it just sees two files matching test_* and grabs all tests in both of them, ignoring what __init__.py tells him to import.

So right now I have to do both py.test2 mypkg/test/test_py2.py and py.test3 mypkg/test/test_py3.py. Is there a way to set up the whole thing so that py.test2 mypkg and py.test3 mypkg would “just work”?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:07:17+00:00Added an answer on June 4, 2026 at 10:07 am

    If you can then making your modules importable on all interpreters and skipping tests as appropriate is a common solution. Otherwise you can put the following as “conftest.py” into the test directory:

    import sys
    py3 = sys.version_info[0] >= 3
    
    class DummyCollector(pytest.collect.File):
       def collect(self):
          return []
    
    def pytest_pycollect_makemodule(path, parent):
      bn = path.basename 
      if "py3" in bn and not py3 or ("py2" in bn and py3):
         return DummyCollector(path, parent=parent)
    

    This gets picked up a project-specific plugin and will properly ignore a test module with a filename containing a “py2” or “py3” substring on the wrong interpreter version. Of course you can refine it to rather have an explicit list directly in the conftest.py file instead of checking the filename etc.pp.

    HTH, holger

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an SSIS package that essentially takes data from multiple sources and
I have written a toolbar that runs on the taskbar. Unfortunately, after it is
Many data analysts that I respect use version control. For example: http://github.com/hadley/ See comments
I have written a game engine in C++, however I would like to package
We have written a software package for a particular niche industry. This package has
I have written an Apex class in a Salesforce managed package which uses the
I have written a class in python that implements __str__(self) but when I use
i have written an application that needs to process outgoing calls. Everything works fine,
Hey everyone, I have written a script that downloads a zip file from a
I have written a python package which consists of several .py files which contain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.