Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify code with ruff --fix #583

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
toxpython: 'python3.6'
python_arch: 'x64'
tox_env: 'py36-pytest70-xdist250-coverage62'
os: 'ubuntu-latest'
os: 'ubuntu-20.04'
Pierre-Sassoulas marked this conversation as resolved.
Show resolved Hide resolved
- name: 'py36-pytest70-xdist250-coverage62 (windows)'
python: '3.6'
toxpython: 'python3.6'
Expand Down
2 changes: 1 addition & 1 deletion examples/adhoc-layout/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_add():
assert example.add(1, 1) == 2
assert not example.add(0, 1) == 2
assert example.add(0, 1) != 2
2 changes: 1 addition & 1 deletion examples/src-layout/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def test_add():
assert example.add(1, 1) == 2
assert not example.add(0, 1) == 2
assert example.add(0, 1) != 2
58 changes: 28 additions & 30 deletions src/pytest_cov/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,34 @@ def init():
cov_branch = True if os.environ.get('COV_CORE_BRANCH') == 'enabled' else None
cov_context = os.environ.get('COV_CORE_CONTEXT')

if cov_datafile:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this change. I think it makes this block of hairy code worse:

  • harder to git blame
  • conditions are harder to read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if _active_cov:
cleanup()
# Import what we need to activate coverage.
import coverage

# Determine all source roots.
if cov_source in os.pathsep:
cov_source = None
else:
cov_source = cov_source.split(os.pathsep)
if cov_config == os.pathsep:
cov_config = True

# Activate coverage for this process.
cov = _active_cov = coverage.Coverage(
source=cov_source,
branch=cov_branch,
data_suffix=True,
config_file=cov_config,
auto_data=True,
data_file=cov_datafile
)
cov.load()
cov.start()
if cov_context:
cov.switch_context(cov_context)
cov._warn_no_data = False
cov._warn_unimported_source = False
return cov
if not cov_datafile:
return None

if _active_cov:
cleanup()
# Import what we need to activate coverage.
import coverage

# Determine all source roots.
cov_source = None if cov_source in os.pathsep else cov_source.split(os.pathsep)
if cov_config == os.pathsep:
cov_config = True
# Activate coverage for this process.
cov = _active_cov = coverage.Coverage(
source=cov_source,
branch=cov_branch,
data_suffix=True,
config_file=cov_config,
auto_data=True,
data_file=cov_datafile
)
cov.load()
cov.start()
if cov_context:
cov.switch_context(cov_context)
cov._warn_no_data = False
cov._warn_unimported_source = False
return cov


def _cleanup(cov):
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def pytest_sessionstart(self, session):
self.pid = os.getpid()
if self._is_worker(session):
nodeid = (
session.config.workerinput.get('workerid', getattr(session, 'nodeid'))
session.config.workerinput.get('workerid', session.nodeid)
)
self.start(engine.DistWorker, session.config, nodeid)
elif not self._started:
Expand Down
7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ commands =

[testenv:check]
deps =
docutils
check-manifest
colorama # TODO Remove when isort > v6.0.0b2 is released.
docutils
flake8
readme-renderer
pygments
isort
pygments
readme-renderer
skip_install = true
usedevelop = false
commands =
Expand Down