Opened 2 years ago

Closed 23 months ago

#64241 closed enhancement (fixed)

python portgroup: add opt-in test support

Reported by: mascguy (Christopher Nielsen) Owned by: mascguy (Christopher Nielsen)
Priority: Normal Milestone:
Component: ports Version: 2.7.1
Keywords: tests Cc: reneeotten (Renee Otten)
Port: python

Description

Presently, Python ports must include the following copy-pasta, to enable tests:

    depends_test-append \
                        port:py${python.version}-pytest

    test.run            yes
    test.cmd            py.test-${python.branch}
    test.target
    test.env-append     PYTHONPATH=${worksrcpath}/build/lib

So, it might make sense to add opt-in support for testing to the Python portgroup, to eliminate duplication of the above.

Proposed option, to enable opt-in: python.tests (default to no)

Of note, it's understood that some Python ports require additional test-specific dependencies, beyond just py-test. And this enhancement won't eliminate that.

However, it would still reduce portfile copy-pasta, and allow us to further simplify our Python ports.

Change History (3)

comment:1 Changed 2 years ago by reneeotten (Renee Otten)

I like that idea and it's certainly worth considering to add something along these lines as it would indeed simplify the ports. I'd probably in favor of having python.tests with options like pytest or nose to specify which testing framework to use. Ideally one would be able to check whether supported_archs noarch is set which would give the code you give above, if it's not set one would use

pre-test {
    test.env    PYTHONPATH=[glob -nocomplain ${worksrcpath}/build/lib*]
}

instead of the test.env-append given above. I haven't looked whether that's an easy thing to do, but we can investigate that a bit more. I can take a look if you want, but that's probably not going to happen until Christmas time.

comment:2 in reply to:  1 Changed 2 years ago by mascguy (Christopher Nielsen)

Replying to reneeotten:

I like that idea and it's certainly worth considering to add something along these lines as it would indeed simplify the ports. I'd probably in favor of having python.tests with options like pytest or nose to specify which testing framework to use. Ideally one would be able to check whether supported_archs noarch is set which would give the code you give above, if it's not set one would use

pre-test {
    test.env    PYTHONPATH=[glob -nocomplain ${worksrcpath}/build/lib*]
}

instead of the test.env-append given above. I haven't looked whether that's an easy thing to do, but we can investigate that a bit more.

Sounds great Renee. And I'm happy to do the work on this; just wanted to facilitate collaborative discussion, to ensure the various bases are covered.

I'll take a stab at all of this over the next week or two. Once the work is reasonably complete, I'll submit a PR for formal review.

And thanks as always for your feedback and insights!

comment:3 Changed 23 months ago by reneeotten (Renee Otten)

Resolution: fixed
Status: assignedclosed

In ce0951b4738f44d7413c05bc5f3a5e7b55b1f42f/macports-ports (master):

python PG: add code for setting-up a test phase

  • add "python.test_framework" option to the python PG. Currently supported frameworks are: "pytest" (default), "nose", and "unittest".

When "test.run yes" is set, a test-phase will be set-up for the pyXY
subports. The required testing-framework dependency is added, PYTHONPATH
is set, and the test.cmd / test.args are set depending on the selected
framework.

Closes: #64241

Note: See TracTickets for help on using tickets.