
GITHUB . COM {
}
Detected CMS Systems:
- Wordpress (2 occurrences)
Title:
Don't auto-discover tests in particular folders Β· Issue #12749 Β· pytest-dev/pytest
Description:
This inspired by a discussion: #12748 What's the problem this feature will solve? We have a project that's about a different kind of test. We have a lot of classes with "Test" in ...
Website Age:
17 years and 8 months (reg. 2007-10-09).
Matching Content Categories {π}
- Education
- Transportation
- Automotive
Content Management System {π}
What CMS is github.com built with?
Github.com uses WORDPRESS.
Traffic Estimate {π}
What is the average monthly size of github.com audience?
ππ Tremendous Traffic: 10M - 20M visitors per month
Based on our best estimate, this website will receive around 10,653,634 visitors per month in the current month.
check SE Ranking
check Ahrefs
check Similarweb
check Ubersuggest
check Semrush
How Does Github.com Make Money? {πΈ}
Subscription Packages {π³}
We've located a dedicated page on github.com that might include details about subscription plans or recurring payments. We identified it based on the word pricing in one of its internal links. Below, you'll find additional estimates for its monthly recurring revenues.How Much Does Github.com Make? {π°}
Subscription Packages {π³}
Prices on github.com are in US Dollars ($).
They range from $4.00/month to $21.00/month.
We estimate that the site has approximately 5,316,035 paying customers.
The estimated monthly recurring revenue (MRR) is $22,327,346.
The estimated annual recurring revenues (ARR) are $267,928,149.
Wordpress Themes and Plugins {π¨}
What WordPress theme does this site use?
It is strange but we were not able to detect any theme on the page.
What WordPress plugins does this website use?
It is strange but we were not able to detect any plugins on the page.
Keywords {π}
test, tests, classes, pytest, freergit, commented, nicoddemus, src, class, code, directory, imported, solution, collected, react, production, testament, issue, wpietri, start, file, option, testingignore, member, considered, def, sign, dont, collect, excludepaths, contributor, files, excluded, content, pull, projects, discussion, problem, set, called, testfoo, srcpytestcollectionissuedomainpy, testpaths, run, secondbest, paths, discover, things, domain, github,
Topics {βοΈ}
freergit/dont-auto-discover-feat open source tbh testing/ignore called test_never_ran nicoddemus edits member collect time skips file src/pytest_collection_issue/domain comment metadata assignees pytest collects test_foo auto-discover tests entire ignore dir including manually adding importing production classes default disable discovery excluded testing/ignore src/pytest_collection_issue/domain type projects projects milestone py class testament internally excluding tests considered tests automatically production code import ignore production class testing/ignore /testing/ignore class testament import classes main code imported classes classes imported telling pytest test code testament = ignore class testcollector discover things pytest tests $ pytest tests limiting discovery assert true test file some_property = testament def test_foo domain imports classes defined testing directory test classes issue def test_always_fails test_foo namespace minimal shenanigans
Payment Methods {π}
- Braintree
Questions {β}
- Already have an account?
- In your example you excluded testing/ignore, correct?
- What's the problem this feature will solve?
Schema {πΊοΈ}
DiscussionForumPosting:
context:https://schema.org
headline:Don't auto-discover tests in particular folders
articleBody:<!--
Thanks for suggesting a feature!
Quick check-list while suggesting features:
-->
This inspired by a discussion: https://github.com/pytest-dev/pytest/discussions/12748
#### What's the problem this feature will solve?
We have a project that's about a different kind of test. We have a lot of classes with "Test" in the name, including some that start with "Test". We would also like to organize some of our pytest tests in classes whose names start with "Test". We distinguish them by directory; all our pytest tests are in `tests`, and all our production code is in `src`. We'd like an easy way to set this up with no distortion to our production code and minimal shenanigans in the test code, while getting no warnings.
Naively one might think that limiting discovery to a particular directory, as with `pytest tests` or `testpaths=["tests"]`. However, if a production file called TestFoo is imported from production code into test code, it will still be discovered, resulting in a warning like:
```
src/pytest_collection_issue/domain.py:6
src/pytest_collection_issue/domain.py:6: PytestCollectionWarning: cannot collect test class 'Testament' because it has a __init__ constructor (from: tests/test_domain.py)
class Testament(object):
```
#### Describe the solution you'd like
For me, the best solution is just to by default disable discovery beyond the requested `testpaths`. Trying to run something just because it's included from wherever strikes me as counterintuitive behavior. If somebody needs that behavior, perhaps an option like `discover_imports` would be useful.
The second-best solution would be an option where we can specify paths to definitely not discover things in. E.g.:
```
testpaths = ["tests"]
excludepaths = ["src"]
```
#### Alternative Solutions
There are many ways to solve this, including manually adding a `__test__ = false` to each production class, using a marker mixin like NotAPytestTest to achieve the same end, importing production classes into the tests under different names, doing only local imports, or renaming our test classes. All of these are a little clunky, and require people to remember a ritual under certain circumstances.
The solution I went with is to put
```
for a_class in [i[1] for i in (globals().items()) if inspect.isclass(i[1])]:
if a_class.__name__.startswith('Test'):
a_class.__test__ = False
```
after my domain imports and before my test classes. It still seems clunky to me, but only has to happen once per file of tests. I think it would be better still if this could be fixed in one spot, or have it work by default.
#### Additional context
Please see [this GitHub discussion](https://github.com/pytest-dev/pytest/discussions/12748) and [this example repository](https://github.com/wpietri/pytest-collection-issue) that demonstrates the problem.
author:
url:https://github.com/wpietri
type:Person
name:wpietri
datePublished:2024-08-29T16:06:10.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:11
url:https://github.com/12749/pytest/issues/12749
context:https://schema.org
headline:Don't auto-discover tests in particular folders
articleBody:<!--
Thanks for suggesting a feature!
Quick check-list while suggesting features:
-->
This inspired by a discussion: https://github.com/pytest-dev/pytest/discussions/12748
#### What's the problem this feature will solve?
We have a project that's about a different kind of test. We have a lot of classes with "Test" in the name, including some that start with "Test". We would also like to organize some of our pytest tests in classes whose names start with "Test". We distinguish them by directory; all our pytest tests are in `tests`, and all our production code is in `src`. We'd like an easy way to set this up with no distortion to our production code and minimal shenanigans in the test code, while getting no warnings.
Naively one might think that limiting discovery to a particular directory, as with `pytest tests` or `testpaths=["tests"]`. However, if a production file called TestFoo is imported from production code into test code, it will still be discovered, resulting in a warning like:
```
src/pytest_collection_issue/domain.py:6
src/pytest_collection_issue/domain.py:6: PytestCollectionWarning: cannot collect test class 'Testament' because it has a __init__ constructor (from: tests/test_domain.py)
class Testament(object):
```
#### Describe the solution you'd like
For me, the best solution is just to by default disable discovery beyond the requested `testpaths`. Trying to run something just because it's included from wherever strikes me as counterintuitive behavior. If somebody needs that behavior, perhaps an option like `discover_imports` would be useful.
The second-best solution would be an option where we can specify paths to definitely not discover things in. E.g.:
```
testpaths = ["tests"]
excludepaths = ["src"]
```
#### Alternative Solutions
There are many ways to solve this, including manually adding a `__test__ = false` to each production class, using a marker mixin like NotAPytestTest to achieve the same end, importing production classes into the tests under different names, doing only local imports, or renaming our test classes. All of these are a little clunky, and require people to remember a ritual under certain circumstances.
The solution I went with is to put
```
for a_class in [i[1] for i in (globals().items()) if inspect.isclass(i[1])]:
if a_class.__name__.startswith('Test'):
a_class.__test__ = False
```
after my domain imports and before my test classes. It still seems clunky to me, but only has to happen once per file of tests. I think it would be better still if this could be fixed in one spot, or have it work by default.
#### Additional context
Please see [this GitHub discussion](https://github.com/pytest-dev/pytest/discussions/12748) and [this example repository](https://github.com/wpietri/pytest-collection-issue) that demonstrates the problem.
author:
url:https://github.com/wpietri
type:Person
name:wpietri
datePublished:2024-08-29T16:06:10.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:11
url:https://github.com/12749/pytest/issues/12749
Person:
url:https://github.com/wpietri
name:wpietri
url:https://github.com/wpietri
name:wpietri
InteractionCounter:
interactionType:https://schema.org/CommentAction
userInteractionCount:11
interactionType:https://schema.org/CommentAction
userInteractionCount:11
External Links {π}(3)
Analytics and Tracking {π}
- Site Verification - Google
Libraries {π}
- Clipboard.js
- D3.js
- Lodash
Emails and Hosting {βοΈ}
Mail Servers:
- aspmx.l.google.com
- alt1.aspmx.l.google.com
- alt2.aspmx.l.google.com
- alt3.aspmx.l.google.com
- alt4.aspmx.l.google.com
Name Servers:
- dns1.p08.nsone.net
- dns2.p08.nsone.net
- dns3.p08.nsone.net
- dns4.p08.nsone.net
- ns-1283.awsdns-32.org
- ns-1707.awsdns-21.co.uk
- ns-421.awsdns-52.com
- ns-520.awsdns-01.net